~1KB Bundle Size
Smallest variant library available. Zero dependencies means nothing else to download.
css-variants is a JavaScript library for managing CSS class variants with full TypeScript support. It generates CSS classes at runtime based on declarative variant definitions like color, size, and state.
Why developers choose css-variants:
Use the cv() function to define variants declaratively. The function returns a callable that generates CSS class strings.
import { cv } from 'css-variants'
const button = cv({ base: 'px-4 py-2 rounded font-medium transition-colors', variants: { color: { primary: 'bg-blue-600 text-white hover:bg-blue-700', secondary: 'bg-gray-200 text-gray-800 hover:bg-gray-300', }, size: { sm: 'text-sm px-3 py-1.5', lg: 'text-lg px-6 py-3', }, }, defaultVariants: { color: 'primary', size: 'sm', },})
button() // Uses defaults: primary + smbutton({ color: 'secondary', size: 'lg' }) // Overrides: secondary + lg~1KB Bundle Size
Smallest variant library available. Zero dependencies means nothing else to download.
3-11x Faster Runtime
Optimized algorithms outperform CVA and tailwind-variants in all benchmarks.
Full TypeScript Support
Complete type inference. Get autocomplete for variant props without manual type definitions.
Framework and CSS Agnostic
Works with React, Vue, Svelte, Solid and any CSS approach (Tailwind, CSS Modules, vanilla).
| Library | Bundle Size | Performance |
|---|---|---|
| css-variants | ~1KB | Baseline |
| CVA | ~2KB | 3-7x slower |
| tailwind-variants | ~5KB | 5-11x slower |
Yes. css-variants is CSS-framework agnostic. Use it with any CSS approach:
// Tailwind CSSconst button = cv({ base: 'px-4 py-2 rounded', variants: { color: { primary: 'bg-blue-600 text-white' } },})
// Vanilla CSSconst button = cv({ base: 'btn', variants: { color: { primary: 'btn-primary' } },})
// CSS Modulesimport styles from './Button.module.css'const button = cv({ base: styles.btn, variants: { color: { primary: styles.primary } },})React
<button className={button({ color: 'primary' })}> Click me</button>Vue
<button :class="button({ color: 'primary' })"> Click me</button>Svelte
<button class={button({ color: 'primary' })}> Click me</button>Solid
<button class={button({ color: 'primary' })}> Click me</button>