Token导航 LogoToken导航TokenDH.com
开发规范只读github未标认证来源可访问clear审计通过

tailwind-best-practicesTailwind CSS 最佳实践

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

4,301

周安装

174

GitHub Stars

33

下载量

1,350
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:tailwind-best-practices(Tailwind CSS 最佳实践)
来源仓库:https://github.com/asyrafhussin/agent-skills
仓库路径:skills/tailwind-best-practices
安装命令:
npx skills add https://github.com/asyrafhussin/agent-skills --skill tailwind-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/asyrafhussin/agent-skills --skill tailwind-best-practices

简介

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。

  • 适合生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构或定位布局问题。
  • 使用时需结合项目现有设计系统、路由和构建方式,避免生成孤立片段;涉及页面改动时应配合本地预览和构建检查。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • tailwind-best-practices 属于开发规范类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Tailwind CSS Best Practices

Comprehensive patterns for building consistent, maintainable interfaces with Tailwind CSS v3.4+ and v4. Contains 29 rules covering responsive design, dark mode, component patterns, configuration, and v4 migration.

Metadata

  • Version: 1.0.0
  • Framework: Tailwind CSS v3.4+ / v4.0+
  • Rule Count: 29 rules across 8 categories
  • License: MIT
  • Documentation: tailwindcss.com/docs

Step 1: Detect Tailwind Version

Always check the version before giving any advice. v3 and v4 are fundamentally different.

Check package.json for the installed version:

{ "tailwindcss": "^3.x" }  // → v3 rules apply
{ "tailwindcss": "^4.x" }  // → v4 rules apply

Also check for these signals:

SignalVersion
tailwind.config.js existsv3
@import "tailwindcss" in CSSv4
@tailwindcss/vite in dependenciesv4
@tailwindcss/postcss in dependenciesv4
@theme {} block in CSSv4

If v3: Apply resp-, dark-, comp-, config- rules. Note that v4 is available. If v4: Apply v4- rules. tailwind.config.js patterns do NOT apply — use @theme {} instead. If migrating v3 → v4: Follow v4-migration rules directly.

When to Apply

Reference these guidelines when:

  • Writing responsive layouts
  • Implementing dark mode
  • Creating reusable component styles
  • Configuring Tailwind (v3 or v4)
  • Migrating a project from v3 to v4
  • Setting up a new project with v4

Rule Categories by Priority

PriorityCategoryImpactPrefixVersion
1Responsive DesignCRITICALresp-v3 / v4
2Dark ModeCRITICALdark-v3 / v4
3Component PatternsHIGHcomp-v3 / v4
4Custom ConfigurationHIGHconfig-v3
5V4 & MigrationHIGHv4-v4 only
6Spacing & TypographyMEDIUMspace-v3 / v4
7AnimationMEDIUManim-v3 / v4
8PerformanceLOWperf-v3 / v4

Quick Reference

1. Responsive Design (CRITICAL)

  • resp-mobile-first - Mobile-first approach
  • resp-breakpoints - Use breakpoints correctly
  • resp-container - Container patterns
  • resp-grid-flex - Grid vs Flexbox decisions
  • resp-hidden-shown - Conditional display

2. Dark Mode (CRITICAL)

  • dark-setup - Configure dark mode
  • dark-classes - Apply dark mode classes
  • dark-toggle - Implement dark mode toggle
  • dark-system-preference - Respect system preference
  • dark-colors - Design for both modes

3. Component Patterns (HIGH)

  • comp-clsx-cn - Conditional classes utility
  • comp-variants - Component variants pattern
  • comp-slots - Slot-based components
  • comp-composition - Composing utilities

4. Custom Configuration — v3 only (HIGH)

  • config-extend - Extend vs override theme
  • config-colors - Custom color palette
  • config-fonts - Custom fonts
  • config-screens - Custom breakpoints
  • config-plugins - Using plugins

5. V4 & Migration (HIGH)

  • v4-installation - Install v4 with Vite or PostCSS, @source, @reference
  • v4-theme-configuration - Replace tailwind.config.js with @theme {} in CSS
  • v4-custom-utilities - @utility, @custom-variant, @variant, @plugin
  • v4-migration - Step-by-step v3 → v4 migration with renamed utilities, starting:, forced-colors:

6. Spacing & Typography (MEDIUM)

  • space-consistent - Consistent spacing scale
  • space-margins - Margin patterns
  • space-padding - Padding patterns
  • typo-scale - Typography scale
  • typo-line-height - Line height

7. Animation (MEDIUM)

  • anim-transitions - Transition utilities
  • anim-keyframes - Custom keyframes
  • anim-reduced-motion - Respect motion preferences

8. Performance (LOW)

  • perf-purge - Content configuration
  • perf-jit - JIT mode benefits
  • perf-arbitrary - Arbitrary values usage

Essential Patterns

Mobile-First Responsive Design

// ✅ Mobile-first: start with mobile, add larger breakpoints
<div className="
  w-full           // Mobile: full width
  md:w-1/2         // Tablet: half width
  lg:w-1/3         // Desktop: third width
">
  <p className="
    text-sm          // Mobile: small text
    md:text-base     // Tablet: base text
    lg:text-lg       // Desktop: large text
  ">
    Content
  </p>
</div>

// ❌ Don't think desktop-first
<div className="w-1/3 md:w-1/2 sm:w-full">  // Confusing

Dark Mode Implementation

v3 — tailwind.config.js:

module.exports = { darkMode: 'class' }

v4 — CSS only, no config file:

@import "tailwindcss";
/* dark mode is class-based by default in v4 — no config needed */

Component — identical in both versions:

<div className="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
  <h2 className="text-gray-900 dark:text-white">Title</h2>
  <p className="text-gray-600 dark:text-gray-400">Description</p>
</div>

function toggleDarkMode() {
  document.documentElement.classList.toggle('dark')
}

Conditional Classes with clsx/cn

import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'

// cn utility - merges Tailwind classes intelligently
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

// Usage
interface ButtonProps {
  variant?: 'primary' | 'secondary' | 'danger'
  size?: 'sm' | 'md' | 'lg'
  className?: string
  children: React.ReactNode
}

function Button({ variant = 'primary', size = 'md', className, children }: ButtonProps) {
  return (
    <button
      className={cn(
        // Base styles
        'inline-flex items-center justify-center rounded-md font-medium transition-colors',
        'focus:outline-none focus:ring-2 focus:ring-offset-2',

        // Variants
        {
          'bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500':
            variant === 'primary',
          'bg-gray-100 text-gray-900 hover:bg-gray-200 focus:ring-gray-500':
            variant === 'secondary',
          'bg-red-600 text-white hover:bg-red-700 focus:ring-red-500':
            variant === 'danger',
        },

        // Sizes
        {
          'px-3 py-1.5 text-sm': size === 'sm',
          'px-4 py-2 text-base': size === 'md',
          'px-6 py-3 text-lg': size === 'lg',
        },

        // Allow override
        className
      )}
    >
      {children}
    </button>
  )
}

Theme Configuration — v3 vs v4

v3 — tailwind.config.js:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./resources/**/*.{blade.php,js,ts,jsx,tsx}'],
  darkMode: 'class',
  theme: {
    extend: {
      colors: { primary: { 500: '#0ea5e9', 600: '#0284c7' } },
      fontFamily: { sans: ['Inter', 'sans-serif'] },
      spacing: { '18': '4.5rem' },
    },
  },
  plugins: [require('@tailwindcss/forms')],
}

v4 — app.css only, no JS config:

@import "tailwindcss";

@theme {
  --color-primary-500: #0ea5e9;
  --color-primary-600: #0284c7;
  --font-sans: Inter, sans-serif;
  --spacing-18: 4.5rem;
  --breakpoint-3xl: 1920px;
}
See v4-theme-configuration and v4-migration rules for full details.

Responsive Grid Layout

// Product grid - responsive columns
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
  {products.map(product => (
    <ProductCard key={product.id} product={product} />
  ))}
</div>

// Dashboard layout - sidebar + main
<div className="flex flex-col lg:flex-row min-h-screen">
  <aside className="
    w-full lg:w-64
    bg-gray-900
    lg:min-h-screen
  ">
    <nav>...</nav>
  </aside>
  <main className="flex-1 p-4 lg:p-8">
    <div className="max-w-7xl mx-auto">
      {children}
    </div>
  </main>
</div>

Form Styling

<form className="space-y-6">
  <div>
    <label htmlFor="email" className="block text-sm font-medium text-gray-700 dark:text-gray-300">
      Email
    </label>
    <input
      type="email"
      id="email"
      className="
        mt-1 block w-full rounded-md
        border-gray-300 dark:border-gray-600
        bg-white dark:bg-gray-800
        text-gray-900 dark:text-white
        shadow-sm
        focus:border-blue-500 focus:ring-blue-500
        disabled:bg-gray-100 disabled:cursor-not-allowed
      "
    />
  </div>

  <button
    type="submit"
    className="
      w-full flex justify-center
      py-2 px-4
      border border-transparent rounded-md
      shadow-sm text-sm font-medium
      text-white bg-blue-600
      hover:bg-blue-700
      focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500
      disabled:opacity-50 disabled:cursor-not-allowed
    "
  >
    Submit
  </button>
</form>

Animations with Reduced Motion

// Respect user's motion preferences
<div className="
  transition-transform duration-300
  hover:scale-105
  motion-reduce:transition-none
  motion-reduce:hover:transform-none
">
  Card content
</div>

// Custom animation
<div className="animate-fade-in motion-reduce:animate-none">
  Content
</div>
// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      keyframes: {
        'fade-in': {
          '0%': { opacity: '0' },
          '100%': { opacity: '1' },
        },
      },
      animation: {
        'fade-in': 'fade-in 0.3s ease-out',
      },
    },
  },
}

How to Use

Always run Step 1 (version detection) first, then read the relevant rule files:

v3 projects:

rules/config-extend-theme.md
rules/dark-setup.md
rules/comp-clsx-cn.md
rules/resp-mobile-first.md

v4 projects:

rules/v4-installation.md
rules/v4-theme-configuration.md
rules/v4-custom-utilities.md

Migrating v3 → v4:

rules/v4-migration.md

References

Ecosystem Tools

  • Tailwind CSS IntelliSense - VS Code autocomplete and linting
  • Prettier Plugin - Automatic class sorting
  • tailwind-merge - Conflict-free class merging
  • clsx - Conditional class utility
  • CVA - Component variant system

License

MIT License - See repository for full license text.

This skill is part of the Agent Skills collection, providing AI-powered development assistance with industry best practices.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

32.03%
按下载量换算432

Antigravity

21.06%
按下载量换算284

Gemini CLI

18.26%
按下载量换算247

Codex

12.3%
按下载量换算166

OpenCode

7.87%
按下载量换算106

github-copilot

3.73%
按下载量换算50

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills