--- name: tailwind-patterns description: Tailwind CSS v4 patterns, component styling, dark mode, responsive design, and design system integration. Use when styling components or reviewing CSS. --- # Tailwind Patterns ## Core Approach - Utility-first: compose classes, don't write custom CSS - Extract components, not classes (use React components, not `@apply`) - Consistent spacing/color via design tokens ## Component Patterns ### Button Variants ```tsx const buttonVariants = { primary: 'bg-blue-600 hover:bg-blue-700 text-white', secondary: 'bg-gray-100 hover:bg-gray-200 text-gray-900', danger: 'bg-red-600 hover:bg-red-700 text-white', ghost: 'hover:bg-gray-100 text-gray-700', } interface ButtonProps { variant?: keyof typeof buttonVariants size?: 'sm' | 'md' | 'lg' children: React.ReactNode } export const Button = ({ variant = 'primary', size = 'md', children }: ButtonProps) => { const sizes = { sm: 'px-3 py-1.5 text-sm', md: 'px-4 py-2', lg: 'px-6 py-3 text-lg' } return ( ) } ``` ### Responsive Design ```tsx // Mobile-first approach
``` ### Dark Mode ```tsx // Use dark: prefix

Secondary text

``` ## Design Tokens (v4) ```css /* In CSS — v4 uses CSS variables */ @theme { --color-primary: oklch(0.6 0.2 250); --color-primary-foreground: oklch(1 0 0); --spacing-page: 1.5rem; --radius-card: 0.75rem; } ``` ```tsx // Use in components
``` ## Common Patterns ### Card ```tsx
``` ### Form Input ```tsx ``` ### Skeleton Loader ```tsx
``` ## Forbidden Patterns ```tsx // ❌ Never use @apply for component styles .btn { @apply px-4 py-2; } // extract React component instead // ❌ Arbitrary values when token exists
// use text-blue-500 // ❌ Inline styles with Tailwind
```