
tailwind-best-practices
Tailwind CSS patterns and conventions. 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".
- Installs
- 956
- Last 24h
- +9
- Trending rank
- #9261
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/asyrafhussin/agent-skills --skill tailwind-best-practices- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads tailwind-best-practices automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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:
| Signal | Version |
|---|---|
tailwind.config.js exists | v3 |
@import "tailwindcss" in CSS | v4 |
@tailwindcss/vite in dependencies | v4 |
@tailwindcss/postcss in dependencies | v4 |
@theme {} block in CSS | v4 |
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
| Priority | Category | Impact | Prefix | Version |
|---|---|---|---|---|
| 1 | Responsive Design | CRITICAL | resp- | v3 / v4 |
| 2 | Dark Mode | CRITICAL | dark- | v3 / v4 |
| 3 | Component Patterns | HIGH | comp- | v3 / v4 |
| 4 | Custom Configuration | HIGH | config- | v3 |
| 5 | V4 & Migration | HIGH | v4- | v4 only |
| 6 | Spacing & Typography | MEDIUM | space- | v3 / v4 |
| 7 | Animation | MEDIUM | anim- | v3 / v4 |
| 8 | Performance | LOW | perf- | v3 / v4 |
Quick Reference
1. Responsive Design (CRITICAL)
resp-mobile-first- Mobile-first approachresp-breakpoints- Use breakpoints correctlyresp-container- Container patternsresp-grid-flex- Grid vs Flexbox decisionsresp-hidden-shown- Conditional display
2. Dark Mode (CRITICAL)
dark-setup- Configure dark modedark-classes- Apply dark mode classesdark-toggle- Implement dark mode toggledark-system-preference- Respect system preferencedark-colors- Design for both modes
3. Component Patterns (HIGH)
comp-clsx-cn- Conditional classes utilitycomp-variants- Component variants patterncomp-slots- Slot-based componentscomp-composition- Composing utilities
4. Custom Configuration — v3 only (HIGH)
config-extend- Extend vs override themeconfig-colors- Custom color paletteconfig-fonts- Custom fontsconfig-screens- Custom breakpointsconfig-plugins- Using plugins
5. V4 & Migration (HIGH)
v4-installation- Install v4 with Vite or PostCSS,@source,@referencev4-theme-configuration- Replacetailwind.config.jswith@theme {}in CSSv4-custom-utilities-@utility,@custom-variant,@variant,@pluginv4-migration- Step-by-step v3 → v4 migration with renamed utilities,starting:,forced-colors:
6. Spacing & Typography (MEDIUM)
space-consistent- Consistent spacing scalespace-margins- Margin patternsspace-padding- Padding patternstypo-scale- Typography scaletypo-line-height- Line height
7. Animation (MEDIUM)
anim-transitions- Transition utilitiesanim-keyframes- Custom keyframesanim-reduced-motion- Respect motion preferences
8. Performance (LOW)
perf-purge- Content configurationperf-jit- JIT mode benefitsperf-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-configurationandv4-migrationrules 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
- Tailwind CSS Documentation - Official documentation
- Responsive Design Guide - Mobile-first patterns
- Dark Mode Guide - Theme implementation
- Configuration Guide - Customization
- Tailwind UI - Official component library
- Headless UI - Accessible components
- Heroicons - 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.
FAQ
What does the tailwind-best-practices skill do?
Tailwind CSS patterns and conventions. 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".
How do I install tailwind-best-practices?
Run npx skills add https://github.com/asyrafhussin/agent-skills --skill tailwind-best-practices in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/tailwind-best-practices/ (personal) or .claude/skills/tailwind-best-practices/ (project).
Which AI agents can use tailwind-best-practices?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is tailwind-best-practices safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains tailwind-best-practices?
It is published by asyrafhussin in asyrafhussin/agent-skills. It has 956 recorded installs.
More from asyrafhussin/agent-skills
php-best-practices
asyrafhussin/agent-skills
PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".
react-vite-best-practices
asyrafhussin/agent-skills
React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Triggers on tasks involving Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance.
laravel-best-practices
asyrafhussin/agent-skills
Laravel 13 conventions and best practices. Use when creating controllers, models, migrations, validation, services, or structuring Laravel applications. Triggers on tasks involving Laravel architecture, Eloquent, database, API development, or PHP patterns.
laravel-inertia-react
asyrafhussin/agent-skills
Laravel + Inertia.js + React integration patterns. Use when building Inertia page components, handling forms with useForm, managing shared data, or implementing persistent layouts. Triggers on tasks involving Inertia.js, page props, form handling, or Laravel React integration.
clean-code-principles
asyrafhussin/agent-skills
SOLID principles, design patterns, DRY, KISS, and clean code fundamentals. Use when reviewing architecture, checking code quality, refactoring, or discussing design decisions. Triggers on "review architecture", "check code quality", "SOLID principles", "design patterns", or "clean code".
typescript-react-patterns
asyrafhussin/agent-skills
TypeScript best practices for React development. Use when writing typed React components, hooks, events, refs, or generic components. Triggers on tasks involving TypeScript errors, type definitions, props typing, or type-safe React patterns.
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.