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:
Also check for these signals:
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
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
Dark Mode Implementation
v3 — tailwind.config.js:
v4 — CSS only, no config file:
Component — identical in both versions:
Conditional Classes with clsx/cn
Theme Configuration — v3 vs v4
v3 — tailwind.config.js:
v4 — app.css only, no JS config:
See
v4-theme-configurationandv4-migrationrules for full details.
Responsive Grid Layout
Form Styling
Animations with Reduced Motion
How to Use
Always run Step 1 (version detection) first, then read the relevant rule files:
v3 projects:
v4 projects:
Migrating v3 → v4:
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.


