Skip to content
css-variants css-variants

CSS variant composition for modern JavaScript

Build powerful, flexible component style systems with variants. Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.

Compound Variants

Apply styles when multiple variant conditions are met simultaneously.

compoundVariants: [
{
color: 'primary',
size: 'lg',
class: 'uppercase tracking-wide'
}
]

Boolean Variants

Simple on/off toggles for common states like disabled, loading, or active.

variants: {
disabled: {
true: 'opacity-50 cursor-not-allowed'
}
}

Slot System

Style multi-element components with named slots for complex UI patterns.

slots: ['root', 'header'],
base: {
root: 'card-root',
header: 'card-header'
}

Class Merging

Smart class name merging with the cx utility. Handle conditional classes with ease.

cx('base', condition && 'active', {
'enabled': isEnabled
})

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>