“Tailwind CSS v3/v4 uses an on-demand JIT scanning engine (rewritten in Rust as Tailwind Oxide). Rather than generating a massive 50MB stylesheet of every potential utility up front, the compiler scans template tokens regex-free and produces only the exact CSS rules actually used in your codebase.”
How Tailwind scans templates in Rust and generates exact on-demand CSS in under 10 milliseconds.
// Safelist / Full Class Expression Pattern
const variantStyles = {
primary: 'bg-cyan-500 text-black hover:bg-cyan-400',
secondary: 'bg-slate-800 text-white hover:bg-slate-700',
danger: 'bg-rose-500 text-white hover:bg-rose-600'
};
export function Button({ variant = 'primary', children }) {
return (
<button className={`px-4 py-2 rounded-lg font-semibold transition-colors ${variantStyles[variant]}`}>
{children}
</button>
);
}/* Compiled on-demand CSS */
.bg-cyan-500 { background-color: #06b6d4; }
.hover\:bg-cyan-400:hover { background-color: #22d3ee; }
.bg-rose-500 { background-color: #f43f5e; }Oxide engine monitors file change events in source directories
Fast Rust parser extracts class string candidates from template files
Compiler resolves candidate tokens against theme scales and variant modifiers
Generates micro-CSS AST and writes optimized stylesheet to memory/disk
Completes full compilation cycle in sub-15ms incremental build times
Always write full unbroken class names (e.g. isActive ? "bg-cyan-500" : "bg-slate-500") so the static compiler can detect every candidate token.