Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

tailwind-variants

Compose Tailwind CSS classes conditionally with a variant-first composition API.

Styling and CSSNPM

GitHubWebsite

1. License

License from npm.

github.com/heroui-inc/tailwind-variants

From 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

60 / 100
Gid Score, #995 overall
7.4M
downloads a week, npm
3,335
GitHub stars
45
agent projects use it
tailwind-variants: downloads per weeknpm, tailwind-variants 7,365,193
tailwind-variants: GitHub starsheroui-inc/tailwind-variants 3,335

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

27 projects, 0.9%
25 projects, 0.8%
20 projects, 0.8%
5 projects, 1.5%

Often used with

In 88.9% of its projects
In 86.7% of its projects
In 100.0% of its projects
In 62.2% of its projects
In 55.6% of its projects
In 55.6% of its projects
In 53.3% of its projects
In 53.3% of its projects

tailwind-variants in practice

Strengths

Slots for multi-part components

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.

Class merging without tailwind-merge

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.

A lite build that trades merge for size

Importing from <code>tailwind-variants/lite</code> turns merging off. The FAQ says this build is about 80% smaller.

Variant props inferred from the recipe

<code>VariantProps</code> extracts prop types from a recipe. The docs say slotted components get typed slot functions.

Watch out for

Responsive variants are gone on Tailwind v4

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.

Not every helper merges

<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.

One extend parent per recipe

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
More in Styling and CSS

Alternatives

tailwind-variants This page

MITGid 607.4M/wk

Tailwind Merge

Merge Tailwind CSS classes intelligently without style conflicts.

MITGid 80118M/wk

Compare tailwind-variants with another tool

Get started

Install it.

npm install tailwind-variants

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## 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.