| name | tailwind-v4 |
| description | Expert guidance for styling with Tailwind CSS v4, including modern utility classes, dark mode implementation, responsive design patterns, and component composition. Use this skill when styling HTML, creating UI components, implementing dark mode, or working with Tailwind CSS v4 in any project. |
Tailwind CSS v4 Styling Skill
This skill provides comprehensive guidance for building beautiful, responsive, and accessible user interfaces with Tailwind CSS v4 using modern utility classes and best practices.
Purpose
Provide expert-level Tailwind CSS v4 guidance covering:
- Modern v4 utility classes and deprecation updates
- Dark mode implementation and patterns
- Responsive design with mobile-first approach
- Common component patterns and layouts
- Spacing, typography, and color systems
- Interactive states and transitions
- Best practices for maintainable styling
When to Use
Use this skill when:
- Styling HTML elements or components
- Creating UI components or layouts
- Implementing or updating dark mode
- Working with responsive designs
- Converting from Tailwind v3 to v4
- Building forms, cards, navigation, or other UI patterns
- Applying consistent spacing and typography
- Using Tailwind CSS v4 in any project
Critical v4 Updates
Import Changes
Tailwind v4 uses CSS @import instead of @tailwind directives:
/* ❌ OLD (v3) */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ✅ NEW (v4) */
@import "tailwindcss";
Deprecated Utilities
Tailwind v4 removed deprecated utilities. Always use replacements:
| Deprecated | Replacement | Example |
|---|---|---|
bg-opacity-* |
bg-{color}/* |
bg-black/50 |
text-opacity-* |
text-{color}/* |
text-blue-600/75 |
border-opacity-* |
border-{color}/* |
border-gray-300/60 |
flex-shrink-* |
shrink-* |
shrink-0 |
flex-grow-* |
grow-* |
grow |
overflow-ellipsis |
text-ellipsis |
text-ellipsis |
decoration-slice |
box-decoration-slice |
box-decoration-slice |
decoration-clone |
box-decoration-clone |
box-decoration-clone |
Note: Opacity values remain numeric (0-100), not percentages.
<!-- ✅ CORRECT v4 syntax -->
<div class="bg-blue-500/50 text-gray-900/80 border-gray-300/60">
Content with opacity
</div>
<!-- ❌ WRONG (v3 syntax) -->
<div class="bg-blue-500 bg-opacity-50 text-gray-900 text-opacity-80">
Don't use this
</div>
Read references/utilities.md for complete utility class reference.
Core Principles
1. Use Gap for Spacing in Flex/Grid
Always prefer gap-* utilities over margins for spacing items in flex or grid layouts:
<!-- ✅ CORRECT - Use gap -->
<div class="flex gap-8">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
<!-- ❌ WRONG - Don't use margins -->
<div class="flex">
<div class="mr-8">Item 1</div>
<div class="mr-8">Item 2</div>
<div>Item 3</div>
</div>
2. Mobile-First Responsive Design
Start with mobile styles, then add larger breakpoints:
<!-- Mobile first - text is small by default, larger on bigger screens -->
<h1 class="text-2xl md:text-4xl lg:text-5xl xl:text-6xl">
Responsive Heading
</h1>
<!-- Responsive grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
<div>Item</div>
<div>Item</div>
<div>Item</div>
</div>
Breakpoints: sm (640px), md (768px), lg (1024px), xl (1280px), 2xl (1536px)
3. Always Support Dark Mode
If the project supports dark mode, apply dark mode variants to all components:
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
<!-- Background and text adapt to theme -->
<h2 class="text-2xl font-bold text-gray-900 dark:text-white mb-4">
Title
</h2>
<p class="text-gray-600 dark:text-gray-300">
Content that works in both themes
</p>
</div>
Read references/dark-mode.md for comprehensive dark mode patterns.
4. Think Through Class Order
Group utilities logically for readability:
<!-- Good: Layout → Spacing → Typography → Colors → States -->
<button class="flex items-center gap-2 px-4 py-2 rounded text-lg font-semibold bg-blue-600 text-white hover:bg-blue-700 focus:ring-2 focus:ring-blue-500 transition-colors">
Click Me
</button>
5. Remove Redundant Classes
Don't duplicate inherited properties:
<!-- ❌ WRONG - Redundant classes -->
<div class="flex flex-row">Content</div>
<!-- ✅ CORRECT - flex-row is default -->
<div class="flex">Content</div>
Common Patterns
Card Component
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 border border-gray-200 dark:border-gray-700">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-2">
Card Title
</h3>
<p class="text-gray-600 dark:text-gray-300">
Card content with proper dark mode support.
</p>
</div>
Button Variants
<!-- Primary -->
<button class="bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white px-4 py-2 rounded font-medium transition-colors">
Primary
</button>
<!-- Secondary -->
<button class="bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-900 dark:text-white px-4 py-2 rounded font-medium transition-colors">
Secondary
</button>
<!-- Outline -->
<button class="border-2 border-blue-600 dark:border-blue-400 text-blue-600 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/20 px-4 py-2 rounded font-medium transition-colors">
Outline
</button>
Form Input
<input
type="text"
placeholder="Enter text..."
class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent transition-colors"
>
Navigation Bar
<nav class="bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800 shadow-sm">
<div class="container mx-auto px-4 py-3">
<div class="flex items-center justify-between">
<a href="/" class="text-xl font-bold text-gray-900 dark:text-white">
Logo
</a>
<div class="flex gap-6">
<a href="/about" class="text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors">
About
</a>
<a href="/contact" class="text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors">
Contact
</a>
</div>
</div>
</div>
</nav>
Read references/patterns.md for comprehensive component patterns.
Reference Files
This skill includes detailed reference files:
references/utilities.md- Complete v4 utility class reference, deprecated utilities, color system, layout, typography, borders, shadowsreferences/dark-mode.md- Dark mode implementation, color schemes, toggle patterns, all component variationsreferences/patterns.md- Layout patterns, card components, buttons, forms, navigation, modals
Read the appropriate reference file(s) when working on specific styling tasks.
Working with Existing Projects
Check Existing Conventions
Before writing new styles, check sibling files for patterns:
<!-- If project uses this pattern for buttons: -->
<button class="btn-primary">Click</button>
<!-- Follow the same pattern instead of: -->
<button class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded">
Click
</button>
Extract Repeated Patterns
When seeing the same utilities repeated, suggest creating a component:
<!-- If this appears multiple times: -->
<button class="bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 text-white px-4 py-2 rounded font-medium transition-colors">
Button
</button>
<!-- Suggest extracting to a reusable component -->
Interactive States
Always include hover, focus, and active states:
<button class="
bg-blue-600
hover:bg-blue-700
active:bg-blue-800
focus:ring-2
focus:ring-blue-500
focus:ring-offset-2
dark:bg-blue-500
dark:hover:bg-blue-600
dark:active:bg-blue-700
dark:focus:ring-blue-400
text-white
px-4 py-2
rounded
transition-colors
disabled:opacity-50
disabled:cursor-not-allowed
">
Interactive Button
</button>
Color Usage Best Practices
Recommended Dark Mode Colors
<!-- Backgrounds -->
<div class="bg-white dark:bg-gray-900">Primary</div>
<div class="bg-gray-50 dark:bg-gray-800">Secondary</div>
<div class="bg-gray-100 dark:bg-gray-700">Tertiary</div>
<!-- Text -->
<p class="text-gray-900 dark:text-white">Primary text</p>
<p class="text-gray-700 dark:text-gray-200">Secondary text</p>
<p class="text-gray-600 dark:text-gray-300">Tertiary text</p>
<p class="text-gray-500 dark:text-gray-400">Muted text</p>
<!-- Borders -->
<div class="border-gray-200 dark:border-gray-800">Primary</div>
<div class="border-gray-300 dark:border-gray-700">Secondary</div>
Best Practices Summary
- ✅ Use
@import "tailwindcss"instead of@tailwinddirectives - ✅ Use v4 utility replacements (e.g.,
bg-blue-500/50notbg-opacity-50) - ✅ Use
gap-*for spacing in flex/grid layouts - ✅ Start mobile-first, add breakpoints progressively
- ✅ Always include dark mode variants if project supports it
- ✅ Group utilities logically (layout → spacing → typography → colors → states)
- ✅ Remove redundant classes
- ✅ Include hover, focus, active, and disabled states
- ✅ Add transitions for smooth interactions
- ✅ Check existing project conventions before writing new styles
- ✅ Extract repeated patterns into reusable components
- ✅ Use semantic color scales consistently
- ✅ Test both light and dark modes
- ✅ Consider accessibility (contrast ratios, focus states)
Common Tasks
Styling a New Component
- Start with layout utilities (flex, grid, positioning)
- Add spacing (padding, margin, gap)
- Apply typography (text size, weight, color)
- Add colors (background, text, border)
- Include dark mode variants for all colors
- Add interactive states (hover, focus, active)
- Add transitions for smooth interactions
- Test in both light and dark modes
- Verify responsive behavior at all breakpoints
Converting from v3 to v4
- Replace
@tailwinddirectives with@import "tailwindcss" - Update opacity utilities to slash notation (
bg-blue-500/50) - Replace
flex-shrink-*withshrink-* - Replace
flex-grow-*withgrow-* - Replace
overflow-ellipsiswithtext-ellipsis - Replace decoration utilities with box-decoration variants
- Test all components to ensure styles still work
This skill ensures Tailwind CSS v4 applications have consistent, modern, accessible styling that works beautifully in both light and dark modes across all devices.