Community Tailwind CSS v4 Best Practices
Comprehensive performance optimization guide for Tailwind CSS v4 applications. Contains 44 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Configuring Tailwind CSS v4 build tooling (Vite plugin, PostCSS, CLI)
- Writing or migrating styles using v4's CSS-first approach
- Optimizing CSS bundle size and build performance
- Implementing responsive designs with breakpoints or container queries
- Setting up theming with @theme directive and design tokens
Rule Categories by Priority
Quick Reference
1. Build Configuration (CRITICAL)
build-vite-plugin[blocked] - Use Vite Plugin Over PostCSSbuild-css-import[blocked] - Use CSS Import Over @tailwind Directivesbuild-content-detection[blocked] - Leverage Automatic Content Detectionbuild-node-version[blocked] - Use Node.js 20+ for Optimal Performancebuild-postcss-simplify[blocked] - Remove Redundant PostCSS Pluginsbuild-cli-package[blocked] - Use Correct CLI Package
2. CSS Generation (CRITICAL)
gen-css-first-config[blocked] - Use CSS-First Configuration Over JavaScriptgen-avoid-theme-bloat[blocked] - Avoid Excessive Theme Variablesgen-oklch-colors[blocked] - Use OKLCH Color Space for Vivid Colorsgen-utility-directive[blocked] - Use @utility for Custom Utilitiesgen-dynamic-utilities[blocked] - Use Dynamic Utility Valuesgen-css-variable-syntax[blocked] - Use Parentheses for CSS Variable References
3. Bundle Optimization (HIGH)
bundle-remove-unused-plugins[blocked] - Remove Built-in Pluginsbundle-avoid-preprocessors[blocked] - Avoid Sass/Less Preprocessorsbundle-css-minification[blocked] - Enable CSS Minification in Productionbundle-avoid-cdn-production[blocked] - Avoid Play CDN in Productionbundle-split-critical-css[blocked] - Extract Critical CSS for Initial Render
4. Utility Patterns (HIGH)
util-renamed-utilities[blocked] - Use Renamed Utility Classesutil-important-modifier[blocked] - Use Trailing Important Modifierutil-variant-stacking[blocked] - Use Left-to-Right Variant Stackingutil-explicit-colors[blocked] - Use Explicit Border and Ring Colorsutil-opacity-modifier[blocked] - Use Slash Opacity Modifierutil-gradient-via-none[blocked] - Use via-none to Reset Gradient Stops
5. Component Architecture (MEDIUM-HIGH)
comp-avoid-apply-overuse[blocked] - Avoid Overusing @applycomp-reference-directive[blocked] - Use @reference for CSS Module Integrationcomp-utility-file-scope[blocked] - Understand Utility File Scopecomp-smart-sorting[blocked] - Leverage Smart Utility Sortingcomp-container-customize[blocked] - Customize Container with @utilitycomp-custom-variant[blocked] - Use @custom-variant for Custom Variant Definitions
6. Theming & Design Tokens (MEDIUM)
theme-semantic-tokens[blocked] - Use Semantic Design Token Namestheme-dark-mode-class[blocked] - Use Class-Based Dark Mode for Controltheme-prefix-variables[blocked] - Use Prefix for Variable Namespacingtheme-runtime-variables[blocked] - Leverage Runtime CSS Variablestheme-color-scheme[blocked] - Set color-scheme for Native Dark Modetheme-inline-static[blocked] - Use @theme inline and @theme static for Variable Control
7. Responsive & Adaptive (MEDIUM)
resp-mobile-first[blocked] - Use Mobile-First Responsive Designresp-container-queries[blocked] - Use Container Queries for Component-Level Responsivenessresp-custom-breakpoints[blocked] - Define Custom Breakpoints in @themeresp-hover-capability[blocked] - Pair Hover with Active for Touch-Friendly Interactionsresp-logical-properties[blocked] - Use Logical Properties for RTL Support
8. Animation & Transitions (LOW-MEDIUM)
anim-gpu-accelerated[blocked] - Use GPU-Accelerated Transform Propertiesanim-starting-style[blocked] - Use @starting-style for Entry Animationsanim-gradient-interpolation[blocked] - Use OKLCH Gradient Interpolationanim-3d-transforms[blocked] - Use Built-in 3D Transform Utilities
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions [blocked] - Category structure and impact levels
- Rule template [blocked] - Template for adding new rules
Full Compiled Document
For a complete guide with all rules expanded, see AGENTS.md [blocked].


