UnoCSS — Instant On-Demand Atomic CSS Engine
UnoCSS is the instant on-demand atomic CSS engine. Inspired by Tailwind/Windi but engine-first: define your own utilities, presets, and rules. 5x faster than Tailwind JIT with no parsing or AST overhead.
What it is
UnoCSS is an instant on-demand atomic CSS engine inspired by Tailwind CSS and Windi CSS. Rather than shipping a fixed set of utility classes, UnoCSS generates only the CSS you actually use, at build time, with sub-millisecond performance. It is fully customizable through presets -- you can use Tailwind-compatible classes, Bootstrap-like utilities, or define your own from scratch.
Frontend developers who want atomic CSS with maximum flexibility and minimal build overhead benefit most. UnoCSS works with Vite, Webpack, Nuxt, Next.js, Astro, and other modern build tools.
How it saves time or tokens
UnoCSS scans your source files and generates only the CSS rules that match classes you use. There is no purging step, no large CSS file to ship, and no unused styles. The on-demand approach means the CSS output is always minimal. Build times are sub-millisecond because UnoCSS uses a single-pass regex-based engine rather than a full CSS parser. Hot module replacement is instant in development.
How to use
- Install UnoCSS with Vite:
npm install -D unocss
- Add to your Vite config:
import UnoCSS from 'unocss/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [UnoCSS()]
});
- Import UnoCSS in your entry file and start using utility classes:
import 'virtual:uno.css';
<div class="flex items-center gap-4 p-6 bg-blue-500 text-white rounded-lg">
<h1 class="text-2xl font-bold">Hello UnoCSS</h1>
</div>
Example
// uno.config.ts - Custom rules and shortcuts
import { defineConfig, presetUno, presetAttributify } from 'unocss';
export default defineConfig({
presets: [
presetUno(), // Tailwind-compatible utilities
presetAttributify() // Use utilities as HTML attributes
],
shortcuts: {
'btn': 'px-4 py-2 rounded-lg bg-blue-500 text-white hover:bg-blue-600',
'card': 'p-6 bg-white rounded-xl shadow-md'
},
rules: [
['custom-grid', { display: 'grid', 'grid-template-columns': 'repeat(auto-fit, minmax(200px, 1fr))' }]
]
});
Related on TokRepo
- AI Coding Tools -- Frontend developer utilities on TokRepo
- Design Tools -- UI and design resources for web development
Common pitfalls
- UnoCSS is not a drop-in Tailwind replacement. While presetUno covers most Tailwind utilities, some Tailwind plugins and features may not have direct equivalents. Check preset compatibility before migrating.
- Dynamic class names constructed at runtime (e.g.,
bg-${color}-500) are not detected by the scanner. Use safelist or explicit class lists for dynamic values. - The attributify preset conflicts with some HTML attributes. Test thoroughly if you enable it alongside component libraries that use custom attributes.
Frequently Asked Questions
UnoCSS is faster at build time due to its on-demand engine. Tailwind generates a full CSS file then purges unused styles; UnoCSS only generates what you use. UnoCSS is more flexible with custom presets, but Tailwind has a larger ecosystem and plugin library.
Yes. UnoCSS has an official Nuxt module. Install @unocss/nuxt and add it to your nuxt.config.ts modules array. It works with Nuxt 3 SSR and supports auto-imports of utility classes.
Not directly. Tailwind plugins use Tailwind's internal API. UnoCSS has its own preset system. Many popular Tailwind features have UnoCSS preset equivalents (typography, forms, container queries), but custom Tailwind plugins need to be rewritten as UnoCSS presets.
The attributify preset lets you write utility classes as HTML attributes instead of in the class string. For example, instead of class='text-red-500 font-bold' you write text='red-500' font='bold'. This improves readability for elements with many utilities.
Yes. UnoCSS supports dark mode through the dark: variant, identical to Tailwind's syntax. Use dark:bg-gray-900 to apply styles only in dark mode. Both media-query and class-based dark mode strategies are supported.
Citations (3)
- UnoCSS GitHub Repository— UnoCSS is an instant on-demand atomic CSS engine
- UnoCSS Official Website— Sub-millisecond build performance with single-pass engine
- UnoCSS Presets Documentation— Presets for Tailwind compatibility, attributify, and custom rules
Related on TokRepo
Discussion
Related Assets
HumHub — Open-Source Enterprise Social Network
A flexible, open-source social networking platform built on Yii2 for creating private communities, intranets, and collaboration spaces within organizations.
Dolibarr — Open-Source ERP & CRM for Business Management
A modular open-source ERP and CRM application written in PHP for managing contacts, invoices, orders, inventory, accounting, and more from a single web interface.
PrestaShop — Open-Source PHP E-Commerce Platform
A widely adopted open-source e-commerce platform written in PHP with a rich module marketplace, multi-language support, and a strong European user base.