Back to skills
SKILL.md
Tailwind Best Practices
ASecurityTailwind CSS patterns and conventions, v4 first with v3.4 legacy and migration. Use when writing responsive designs, implementing dark mode, creating reusable component styles, configuring Tailwind, or migrating from v3 to v4. Triggers on tasks involving Tailwind classes, responsive design, dark mode, CSS styling, or "migrate to Tailwind v4".
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added December 2, 2026
Works with
Security analysis
100/100Pro scans all 19 files and shows the line behind each finding
npx -y skills add airshell/laravel-php-to-rust --skill tailwind-best-practices --agent claude-codeAre you the author of Tailwind Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/airshell-tailwind-best-practices)---
name: tailwind-best-practices
description: Tailwind CSS patterns and conventions, v4 first with v3.4 legacy and migration. Use when writing responsive designs, implementing dark mode, creating reusable component styles, configuring Tailwind, or migrating from v3 to v4. Triggers on tasks involving Tailwind classes, responsive design, dark mode, CSS styling, or "migrate to Tailwind v4".
license: MIT
metadata:
author: agent-skills
version: "2.0.0"
tailwindVersion: "4.0+ (tested 4.3); 3.4 legacy"
---
# Tailwind CSS Best Practices
Comprehensive patterns for building consistent, maintainable interfaces with Tailwind CSS v4, with v3.4 kept as legacy and a full v3 → v4 migration path. Contains 30 rules covering responsive design, dark mode, component patterns, configuration, v4 setup and migration, and the utilities added in v4.1–4.3.
## Metadata
- **Version:** 2.0.0
- **Framework:** Tailwind CSS v4.0+ (tested on 4.3); v3.4 legacy
- **Rule Count:** 30 rules across 5 categories
- **Last Updated:** November 2026
- **License:** MIT
- **Documentation:** [tailwindcss.com/docs](https://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:
```json
{ "tailwindcss": "^4.x" } // → v4 rules apply (default)
{ "tailwindcss": "^3.x" } // → v3 legacy rules apply
```
For minor-version features (4.1 text shadows, 4.2 logical utilities, 4.3 scrollbars), check the exact version with `npm ls tailwindcss`.
Also check for these signals:
| Signal | Version |
|--------|---------|
| `@import "tailwindcss"` in CSS | v4 |
| `@tailwindcss/vite`, `@tailwindcss/postcss`, `@tailwindcss/cli` or `@tailwindcss/webpack` in dependencies | v4 |
| `@theme {}` block in CSS | v4 |
| `@tailwind base;` directives in CSS | v3 |
| `tailwind.config.js` exists and no `@config` in CSS | v3 |
| `tailwind.config.js` exists and CSS has `@config "..."` | v4 loading a legacy config (mid-migration) |
A `tailwind.config.js` on its own does not prove v3: v4 ignores it unless the CSS loads it with `@config`.
**If v4** (default): Apply `v4-` rules plus `resp-`/`responsive-`, `dark-`, `comp-`/`component-` rules. Use `@theme {}`, not `tailwind.config.js`.
**If v3**: Apply `resp-`/`responsive-`, `dark-`, `comp-`/`component-`, `config-` rules and the v3 (legacy) sections. Mention that v4 is available.
**If migrating v3 → v4**: Follow `v4-migration` directly.
## When to Apply
Reference these guidelines when:
- Writing responsive layouts
- Implementing dark mode
- Creating reusable component styles
- Configuring Tailwind (v4 `@theme`, or v3 config)
- Migrating a project from v3 to v4
- Setting up a new project with v4
## Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules | Version |
|----------|----------|--------|--------|-------|---------|
| 1 | Responsive Design | CRITICAL | `resp-`, `responsive-` | 6 | v4 / v3 |
| 2 | Dark Mode | CRITICAL | `dark-` | 6 | v4 / v3 |
| 3 | Component Patterns | HIGH | `comp-`, `component-` | 7 | v4 / v3 |
| 4 | Custom Configuration | HIGH | `config-` | 6 | v3 legacy (v4 equivalents included) |
| 5 | V4 & Migration | HIGH | `v4-` | 5 | v4 |
## Quick Reference
### 1. Responsive Design (CRITICAL)
- `resp-mobile-first` - Mobile-first approach
- `responsive-breakpoint-order` - Order breakpoints smallest to largest
- `responsive-container-queries` - Container queries (`@container`, `@min-*`/`@max-*`, `@container-size`)
- `responsive-fluid-typography` - Fluid type with `clamp()` and `--text-*` theme values
- `responsive-aspect-ratio` - Aspect ratio utilities
- `responsive-grid-system` - Responsive grid layouts
### 2. Dark Mode (CRITICAL)
- `dark-setup` - Configure dark mode (v4 default is `prefers-color-scheme`)
- `dark-class-strategy` - Manual toggle with `@custom-variant dark` / `darkMode: 'class'`
- `dark-media-strategy` - Follow the system preference
- `dark-color-scheme` - Semantic color tokens for both themes
- `dark-custom-colors` - Custom palettes and pairing
- `dark-transitions` - Smooth theme transitions
### 3. Component Patterns (HIGH)
- `comp-clsx-cn` - Conditional classes with clsx + tailwind-merge
- `component-btn-variants` - Button variants
- `component-card-patterns` - Card patterns
- `component-form-elements` - Form elements
- `component-modals` - Modals and dialogs
- `component-navigation` - Navigation
- `component-tables` - Tables
### 4. Custom Configuration — v3 legacy (HIGH)
- `config-extend-theme` - Extend vs override theme
- `config-custom-colors` - Custom color palette
- `config-custom-fonts` - Custom fonts
- `config-custom-spacing` - Custom spacing
- `config-plugins` - Using plugins (`@plugin` in v4)
- `config-presets` - Sharing configuration (a theme CSS file in v4)
### 5. V4 & Migration (HIGH)
- `v4-installation` - Install v4 with Vite, PostCSS, CLI or webpack; `@source`, `source()`, `@reference`
- `v4-theme-configuration` - `@theme {}` in CSS; `@theme inline`; sharing a theme; `@config` as a bridge
- `v4-custom-utilities` - `@utility`, `@custom-variant`, `@variant`, `@plugin`, `@layer components`
- `v4-migration` - Step-by-step v3 → v4: renames, removals, changed defaults, syntax changes
- `v4-new-utilities` - Built-ins from v4.1–4.3: text shadows, masks, pointer variants, logical properties, scrollbars
## Essential Patterns
### Mobile-First Responsive Design
```tsx
// ✅ 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
**v4 — CSS only, no config file:**
```css
@import "tailwindcss";
/* Default: dark: follows prefers-color-scheme (the OS setting).
For a manual toggle with a .dark class, override the variant: */
@custom-variant dark (&:where(.dark, .dark *));
```
**v3 (legacy) — `tailwind.config.js`:**
```js
module.exports = { darkMode: 'class' }
```
**Component — identical in both versions:**
```tsx
<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>
// Needs the @custom-variant line above (v4) or darkMode: 'class' (v3)
function toggleDarkMode() {
document.documentElement.classList.toggle('dark')
}
```
### Conditional Classes with clsx/cn
```tsx
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-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2',
// Variants
{
'bg-blue-600 text-white hover:bg-blue-700 focus-visible:ring-blue-500':
variant === 'primary',
'bg-gray-100 text-gray-900 hover:bg-gray-200 focus-visible:ring-gray-500':
variant === 'secondary',
'bg-red-600 text-white hover:bg-red-700 focus-visible: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 — v4 vs v3
**v4 — `app.css` only, no JS config:**
```css
@import "tailwindcss";
@plugin "@tailwindcss/forms";
@theme {
--color-primary-500: #0ea5e9;
--color-primary-600: #0284c7;
--font-sans: Inter, sans-serif;
--spacing-header: 4rem; /* numeric values like p-18 need no config */
--breakpoint-3xl: 1920px;
}
```
**v3 (legacy) — `tailwind.config.js`:**
```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')],
}
```
> See `v4-theme-configuration` and `v4-migration` rules for full details.
### Responsive Grid Layout
```tsx
// 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
```tsx
<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
border-gray-300 dark:border-gray-600
bg-white dark:bg-gray-800
text-gray-900 dark:text-white
shadow-xs
focus:border-blue-500 focus:ring-blue-500
user-invalid:border-red-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-xs text-sm font-medium
text-white bg-blue-600
hover:bg-blue-700
cursor-pointer
focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-blue-500
disabled:opacity-50 disabled:cursor-not-allowed
"
>
Submit
</button>
</form>
```
v4 notes: `shadow-xs` is v3's `shadow-sm`; buttons default to `cursor: default`, so add `cursor-pointer` where you want it; `user-invalid:` (v4.1+) shows errors only after the user interacts.
### Animations with Reduced Motion
```tsx
// Respect user's motion preferences
<div className="
transition-transform duration-300
hover:scale-105
motion-reduce:transition-none
motion-reduce:hover:scale-none
">
Card content
</div>
// Custom animation
<div className="animate-fade-in motion-reduce:animate-none">
Content
</div>
```
```css
/* v4 — app.css */
@theme {
--animate-fade-in: fade-in 0.3s ease-out;
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
}
```
```js
// v3 (legacy) — 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:
**v4 projects (default):**
```
rules/v4-installation.md
rules/v4-theme-configuration.md
rules/v4-custom-utilities.md
rules/v4-new-utilities.md
rules/dark-setup.md
rules/comp-clsx-cn.md
rules/resp-mobile-first.md
```
**v3 projects (legacy):**
```
rules/config-extend-theme.md
rules/dark-setup.md
rules/comp-clsx-cn.md
rules/resp-mobile-first.md
```
**Migrating v3 → v4:**
```
rules/v4-migration.md
```
## References
- [Tailwind CSS Documentation](https://tailwindcss.com/docs) - Official documentation
- [Upgrade Guide](https://tailwindcss.com/docs/upgrade-guide) - v3 → v4 changes
- [Responsive Design Guide](https://tailwindcss.com/docs/responsive-design) - Mobile-first patterns
- [Dark Mode Guide](https://tailwindcss.com/docs/dark-mode) - Theme implementation
- [Theme Variables](https://tailwindcss.com/docs/theme) - `@theme` customization
- [Detecting Classes in Source Files](https://tailwindcss.com/docs/detecting-classes-in-source-files) - `@source` and scanning
- [Functions & Directives](https://tailwindcss.com/docs/functions-and-directives) - `@utility`, `@variant`, `@reference`, `@config`, `@plugin`
- [Tailwind Plus](https://tailwindcss.com/plus) - Official component library (formerly Tailwind UI)
- [Headless UI](https://headlessui.com) - Accessible components
- [Heroicons](https://heroicons.com) - Icon library
## 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.
Files in this skill
- AGENTS.md
- README.md
- SKILL.md
- rules/_sections.md
- rules/_template.md
- rules/comp-clsx-cn.md
- rules/component-btn-variants.md
- rules/component-card-patterns.md
- rules/component-form-elements.md
- rules/component-modals.md
- rules/component-navigation.md
- rules/component-tables.md
- rules/config-custom-colors.md
- rules/config-custom-fonts.md
- rules/config-custom-spacing.md
- rules/config-extend-theme.md
- rules/config-plugins.md
- rules/config-presets.md
- rules/dark-class-strategy.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.