A first-class variant API for Tailwind CSS
open sourceMITself-hostablefree
Tailwind Variants lets you define a component's Tailwind CSS classes once as a recipe (base classes, variants such as colour and size, default variants and compound variants that apply only to certain combinations) and call it anywhere with typed props, instead of building long class strings by hand. Slots style each part of a multi-part component from one recipe, extend composes recipes into new ones, and the default build resolves conflicting Tailwind classes itself, while a lite build skips that or takes a merge function you already use. It works with any framework, infers TypeScript props with VariantProps, and is made by HeroUI; its docs compare it with Class Variance Authority and serve llms.txt and a docs MCP server.
Problems it solves
- our button component has a mess of conditional Tailwind class strings for every colour and size
- define size and colour variants for a component once and get typed props for them
- apply extra classes only when two variants combine, like a large primary button
- style each part of a multi-part component, like a card's header and body, from one place
- conflicting Tailwind classes from overrides end up both applied and the wrong one wins
- extend a base component's styles into a new component without copying class lists
- Stitches-style variants for a design system built on Tailwind
Features
- variants, default variants and compound variants for Tailwind classes
- slots for multi-part components
- extend and compose recipes
- built-in conflict resolution for Tailwind classes, or a lite build without it
- typed props inferred with VariantProps
- responsive classes with breakpoint prefixes
- global configuration for design system defaults
- framework-agnostic: works with any UI framework
- llms.txt and a Streamable HTTP MCP server for its docs
Alternatives
The same job
These do what Tailwind Variants does.
- Class Variance Authority A tiny library for building type-safe, variant-driven class names with Tailwind CSS or any other styling approach
