--- name: tailwind-css user-invocable: false description: This skill should be used when the user asks to "style with Tailwind", "add Tailwind classes", "fix Tailwind styles", "use tailwind-variants", "add animations with tw-animate-css", "configure Tailwind v4", "migrate to Tailwind v4", or mentions Tailwind utilities, CSS classes, responsive design, dark mode, gradients, design tokens, or CSS Modules. --- # Tailwind CSS v4 Expert guidance for Tailwind CSS v4, CSS-first configuration, modern utility patterns, and type-safe component styling with tailwind-variants. ## CSS-First Configuration Tailwind CSS v4 eliminates `tailwind.config.ts` in favor of CSS-only configuration. All configuration lives in CSS files using special directives. **Core Directives:** - `@import "tailwindcss"` - Entry point that loads Tailwind - `@theme { }` - Define or extend design tokens - `@theme static { }` - Define tokens that should not generate utilities - `@utility` - Create custom utilities - `@custom-variant` - Define custom variants **Minimal Example:** ```css @import "tailwindcss"; @theme { --color-brand: oklch(0.72 0.11 178); --font-display: "Inter", sans-serif; --spacing-edge: 1.5rem; } ``` All theme tokens defined with `@theme` automatically become available as utility classes. For example, `--color-brand` can be used as `bg-brand`, `text-brand`, `border-brand`, etc. ## ESLint Integration Use `eslint-plugin-better-tailwindcss` for Tailwind CSS v4 class validation and style enforcement. **Correctness Rules (errors):** - `no-conflicting-classes` - Detect classes that override each other - `no-unknown-classes` - Flag classes not registered with Tailwind **Stylistic Rules (warnings):** - `enforce-canonical-classes` - Use standard v4 class names - `enforce-shorthand-classes` - Use abbreviated class versions - `no-deprecated-classes` - Remove outdated class names - `no-duplicate-classes` - Eliminate redundant declarations - `no-unnecessary-whitespace` - Clean up extra spacing **Examples:** ```typescript // ❌ Bad: separate padding
// ✅ Good: shorthand
``` ```typescript // ❌ Bad: separate width/height
// ✅ Good: size utility
``` Run the project's ESLint check after modifying Tailwind classes to validate all changes across the codebase. ## Coding Preferences ### Layout and Spacing **Use `gap` for flex/grid spacing, not `space-x`/`space-y`:** The `gap` utilities handle wrapping correctly, while `space-*` utilities break when flex/grid items wrap to multiple lines. ```typescript // ✅ Good: gap handles wrapping
// ❌ Bad: breaks when items wrap
``` **Prefer `size-*` over separate `w-*`/`h-*` for equal dimensions:** ```typescript // ✅ Good: concise
// ❌ Bad: redundant
``` **Always use `min-h-dvh` instead of `min-h-screen`:** Dynamic viewport height (`dvh`) accounts for mobile browser chrome, while `vh` units ignore it and cause layout issues on mobile Safari. ```typescript // ✅ Good: works on mobile Safari
// ❌ Bad: buggy on mobile Safari
``` **Prefer top/left margins over bottom/right:** Consistent directionality improves layout predictability. ```typescript // ✅ Good: top margin
// ❌ Avoid: bottom margin (unless needed)
``` **Use padding on parent containers instead of bottom margins on last child:** Padding provides consistent spacing without needing `:last-child` selectors. ```typescript // ✅ Good: padding on parent
Item 1
Item 2
Item 3
// ❌ Avoid: margin on children
Item 1
Item 2
Item 3
``` **For max-widths, prefer container scale over pixel values:** ```typescript // ✅ Good: semantic container size
// ❌ Avoid: arbitrary pixel value
``` ### Typography **Avoid `leading-*` classes; use line height modifiers:** Tailwind v4 supports inline line height modifiers with the `text-{size}/{leading}` syntax. ```typescript // ✅ Good: combined size and line height

// ❌ Bad: separate utilities

``` **Font Size Reference:** | Class | Size | | ----------- | ---- | | `text-xs` | 12px | | `text-sm` | 14px | | `text-base` | 16px | | `text-lg` | 18px | | `text-xl` | 20px | ### Colors and Opacity **Use opacity modifier syntax, not separate opacity utilities:** All `*-opacity-*` utilities were removed in Tailwind v4. Use the modifier syntax instead. ```typescript // ✅ Good: opacity modifier

// ❌ Bad: removed in v4
``` **Prefer design tokens over arbitrary hex values:** Check the project's `@theme` configuration before using arbitrary color values. ```typescript // ✅ Good: theme token
// ❌ Avoid: arbitrary hex (check theme first)
``` ### Border Radius Tailwind v4 renamed border radius utilities: | v3 | v4 (equivalent) | Size | | ------------ | --------------- | ---- | | `rounded-sm` | `rounded-xs` | 2px | | `rounded` | `rounded-sm` | 4px | | `rounded-md` | `rounded` | 6px | | `rounded-lg` | `rounded-md` | 8px | Use the v4 names when writing new code. ### Gradients Tailwind v4 renamed gradient utilities and added new gradient types. **Use `bg-linear-*`, not `bg-gradient-*`:** ```typescript // ✅ Good: v4 syntax
// ❌ Bad: removed in v4
``` **New gradient types:** - `bg-radial` - Radial gradients - `bg-conic` - Conic gradients **Example:** ```typescript
``` ### Arbitrary Values **Always prefer Tailwind's predefined scale:** Check the project's `@theme` configuration for available tokens before using arbitrary values. ```typescript // ✅ Good: predefined scale
// ❌ Avoid: arbitrary pixel value
``` **General rule:** Prefer sizing scale over pixel values. Three similar lines of code is better than a premature abstraction. ### Class Merging The common pattern is a `cn` utility combining `clsx` + `tailwind-merge`. **Use `cn` for:** - Static constants: `const CARD_BASE = cn("fixed classes")` - Conditional classes: `cn("base", condition && "conditional")` - Dynamic merging: `cn(baseClasses, className)` - Conflict resolution: `cn("p-4", "p-6")` → `"p-6"` **Do NOT use `cn` for:** - Static strings in `className` attributes: `className="fixed classes"` **Examples:** ```typescript // ✅ Good: static string in className