How Much Faster Is unocss Compared to Tailwind CSS?
This article examines the performance differences between the atomic CSS engines unocss and Tailwind CSS, presenting benchmark tests on a MacBook M1 using Vite and PostCSS setups, analyzing build times, the impact of CSS AST parsing, and discussing practical implications for frontend development.
unocss is regarded as one of the fastest atomic CSS engines because it avoids parsing the CSS abstract syntax tree (AST) and instead extracts tokens directly from the content using regular expressions.
Official benchmarks (2023‑08‑11) show that unocss is roughly 3.7 times faster than Tailwind CSS in build time.
The tests compare two setups: vite + @unocss/vite for unocss versus vite + postcss + tailwindcss for Tailwind. When using unocss as a Vite or webpack plugin, additional directives such as @apply , @screen , and theme() require the @unocss/transformer-directives package.
Benchmark on a MacBook M1 (200 runs, 75% build time) produced the following results (2024/3/5):
2024/3/5 00:19:14
1656 utilities | x200 runs (75% build time)
none 19.92 ms / delta. 0.00 ms
unocss v0.58.5 328.39 ms / delta. 308.47 ms (x1.00)
tailwindcss v3.4.1 798.42 ms / delta. 778.49 ms (x2.52)In this scenario, unocss is about 2.5 times faster than Tailwind CSS, a reduction from the earlier 3.7× gap due to the overhead of CSS AST parsing required for Tailwind directives.
Using the PostCSS approach with @unocss/postcss , the benchmark yielded:
2024/3/5 00:08:25
1656 utilities | x200 runs (75% build time)
none 16.75 ms / delta. 0.00 ms
unocss v0.58.5 679.51 ms / delta. 662.77 ms (x1.00)
tailwindcss v3.4.1 712.55 ms / delta. 695.80 ms (x1.05)When both engines must parse the CSS AST, the performance difference shrinks to about 30 ms, indicating that the main speed advantage of unocss lies in avoiding AST parsing; the remaining gap is due to differences in regular‑expression matching.
Both tools support extensibility via plugins and presets, allowing developers to add custom matching rules. The choice between them ultimately depends on project requirements and ecosystem considerations.
In conclusion, unocss generally offers faster builds, especially when minimizing CSS AST parsing, but upcoming versions of Tailwind CSS (e.g., 4.x written in Rust) may narrow the gap and bring new performance improvements.
Rare Earth Juejin Tech Community
Juejin, a tech community that helps developers grow.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.