--- name: tailwind description: Utility-first CSS framework v4 with CSS-first configuration, @theme directive, and the new Oxide engine. metadata: author: mte90 version: 2.1.0 tags: [css, tailwind, v4, utility-first, oxide-engine] --- ## Overview Tailwind CSS v4 is a complete rewrite of the framework, built on a new Rust-based Oxide engine that's 10x faster. The biggest change: **configuration is now done in CSS**, not JavaScript. No more `tailwind.config.js` for most projects. **Browser support:** Safari 16.4+, Chrome 111+, Firefox 128+ ## The Oxide Engine (Performance) Tailwind v4 uses a new Rust-based **Oxide** engine with dramatically improved performance: | Operation | v3 Speed | v4 Speed (Oxide) | Improvement | |-----------|----------|-----------------|-------------| | Cold build | 8s | 2.1s | **3.78x faster** | | Incremental | 450ms | 51ms | **8.8x faster** | | HMR (Hot Module Reload) | 350ms | 12ms | **28x faster** | | Memory usage | Higher | Lower | ~50% reduction | ### Why It's Faster - **Rust-native**: Core processing in Rust, not JavaScript - **Parallel processing**: Uses all CPU cores efficiently - **Better caching**: Improved incremental build detection - **Optimized CSS generation**: Less overhead in utility generation ### Requirements ```bash # Node.js 18+ required for Oxide engine node --version # Should be 18 or higher # Install with Vite (recommended for best performance) npm install tailwindcss @tailwindcss/vite # Or PostCSS (also fast) npm install tailwindcss @tailwindcss/postcss ``` ## Installation ### Vite (Recommended) ```bash npm install tailwindcss @tailwindcss/vite ``` ```js // vite.config.js import tailwindcss from "@tailwindcss/vite"; export default { plugins: [tailwindcss()], }; ``` ### PostCSS ```bash npm install -D tailwindcss @tailwindcss/postcss ``` ```js // postcss.config.js export default { plugins: { "@tailwindcss/postcss": {}, }, }; ``` ### CLI ```bash npm install -D @tailwindcss/cli npx @tailwindcss/cli -i input.css -o output.css --watch ``` ## Basic Setup ### The CSS File ```css /* input.css */ @import "tailwindcss"; /* Your custom styles below */ ``` That's it. No `@tailwind base/components/utilities` directives—they're gone. ## Theme Configuration with @theme Customize your design tokens directly in CSS using the `@theme` directive: ```css @import "tailwindcss"; @theme { /* Custom colors */ --color-brand: oklch(65% 0.25 250); --color-brand-light: oklch(75% 0.25 250); --color-brand-dark: oklch(55% 0.25 250); /* Custom fonts */ --font-display: "Clash Display", "sans-serif"; --font-body: "Satoshi", "sans-serif"; /* Custom spacing */ --spacing-18: 4.5rem; --spacing-22: 5.5rem; /* Custom breakpoints */ --breakpoint-3xl: 120rem; /* Custom animations */ --animate-fade-in: fade-in 0.5s ease-out; /* Shadow customization */ --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); } @keyframes fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } ``` ### Using Theme Values All theme values become CSS variables automatically: ```css /* These are automatically generated from @theme */ .btn { background-color: var(--color-brand); font-family: var(--font-display); } ``` In your HTML, use them directly as utility values: ```html ``` ## Dark Mode In v4, dark mode uses `@media (prefers-color-scheme)` by default—no config needed. ```html