tailwind-variants
Compose Tailwind CSS classes conditionally with a variant-first composition API.
3. Used by agents' projects
Dependency in 45 public GitHub projects set up for AI coding agents that we scanned (0.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
tailwind-variants.org/llms.txtFrom the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What tailwind-variants does
Tailwind Variants puts class-conflict merging and named per-part slots into one typed recipe function, and offers a separate lite build that drops merging for a smaller bundle.
tailwind-variants popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How tailwind-variants is used
- tailwind-variants is a dependency in 45 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (0.9% of the 4,867 JavaScript/TypeScript ones), #5 of 53 in styling and css.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 80; those are left out of every share on this page.
- The most used alternative in our scan is Tailwind Merge (1,173 projects).
- Projects that use it most often also use Tailwind Merge (88.9%), clsx (86.7%), Tailwind CSS (100.0%).
By coding agent
Often used with
tailwind-variants in practice
Strengths
One recipe can name parts such as <code>base</code>, <code>icon</code> and <code>label</code>, and each part gets its own classes and variants. The docs' comparison table lists slots and compound slots as features that CVA and Windstitch lack.
Since v3.3, the default build resolves conflicts such as <code>px-2</code> versus <code>px-4</code> on its own. The FAQ says to keep tailwind-merge only if your app imports it directly.
Importing from <code>tailwind-variants/lite</code> turns merging off. The FAQ says this build is about 80% smaller.
<code>VariantProps</code> extracts prop types from a recipe. The docs say slotted components get typed slot functions.
Watch out for
The README notes that Tailwind CSS v4 dropped <code>config.content.transform</code>, so responsive variants were removed. You add breakpoint classes to your class names yourself.
<code>cx</code> only concatenates class names. In the lite build, <code>cx</code> is the only one of the three helpers available, so conflicting classes stay side by side.
A recipe can inherit from only one other recipe. To combine several bases, you chain extends or join class strings by hand.
A button recipe with variants, a compound rule and defaults
import { tv } from "tailwind-variants";
const button = tv({
base: "font-medium bg-blue-500 text-white rounded-full active:opacity-80",
variants: {
color: {
primary: "bg-blue-500 text-white",
secondary: "bg-purple-500 text-white",
},
size: {
sm: "text-sm",
md: "text-base",
lg: "px-4 py-3 text-lg",
},
},
compoundVariants: [
{
size: ["sm", "md"],
class: "px-3 py-1",
},
],
defaultVariants: {
size: "md",
color: "primary",
},
});
button({ size: "sm", color: "secondary" });
// => "font-medium rounded-full active:opacity-80 bg-purple-500 text-white text-sm px-3 py-1"More about tailwind-variants
Packages around it
- tailwind-merge: Tailwind class conflict merger
- clsx: Conditional className builder
- tailwindcss: Utility-first CSS framework
- tw-animate-css: Tailwind animation utilities
- svelte: Compiled UI framework
- svelte-check: Svelte type and diagnostics checker
Alternatives
tailwind-variants This page
Merge Tailwind CSS classes intelligently without style conflicts.
Get started
Install it.
npm install tailwind-variantsRules for your agent
## Tailwind Variants
- Import from `tailwind-variants` when conflicting Tailwind classes must merge. Use `tailwind-variants/lite` only when merging is not needed.
- On v3.3+, do not install `tailwind-merge` just for this library. Keep it only if the app imports it directly.
- Use `cn` for everyday merging, `cx` in lite or when classes cannot conflict, and `cnMerge` when a call needs its own config.
- Teach the resolver about custom utilities with `twMergeConfig` in `{ extend, override }` form. Never pass a merge function.
- Define variants inline in `tv`, or mark external variant objects `as const`, so types are inferred.
- On Tailwind v4, write breakpoint prefixes (`sm:`, `md:`) directly in class strings. There is no responsive variant API.
- Give a recipe at most one `extend` parent. Add `slots: {}` only when you need slot functions.