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.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 89cabb3a-356f-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
Windi CSS — On-Demand Utility-First CSS Framework
A next-generation utility-first CSS framework that generates styles on demand at dev time. Inspired by Tailwind CSS with added features like variant groups, shortcuts, and attributify mode for cleaner templates.
ReadySet — SQL Caching Engine for Instant Query Results
Drop-in wire-compatible cache that sits between your application and MySQL or PostgreSQL, automatically keeping query results up to date as underlying data changes.
Cadence — Distributed Workflow Execution Engine by Uber
Cadence is a distributed, scalable, fault-tolerant workflow orchestration engine developed by Uber for executing long-running business logic as durable, stateful workflows that survive process and infrastructure failures.
libvips — Fast Low-Memory Image Processing Library
libvips is a demand-driven, horizontally threaded image processing library that processes images with low memory usage and high speed. It supports over 300 operations and is used as the engine behind Sharp (Node.js) and other image processing tools.