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 Merge

Let the last Tailwind style win.

Styling and CSSNPM

GitHubWebsite

1. License

“The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.”

Keep the MIT copyright and license notice with the package files you ship.

github.com/dcastil/tailwind-merge/blob/main/LICENSE.md

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What Tailwind Merge does

tailwind-merge is a small free JavaScript function for sites styled with Tailwind CSS. When a button or card gets extra style names from the page that uses it, it removes the old names that clash, so the newer style actually shows. Names it does not know stay as they are.

What people build with it

Change one button's look on one screen

Your shared Button has dark colors and small padding; on the pricing page you pass a bigger, purple version, and that one shows instead of being ignored.

Components layered several levels deep

In a design system where a menu item wraps a base option, each level can tweak the style and the last tweak wins.

A red one-off without a new variant

One delete button needs a red background; you pass the red style once instead of teaching the Button a new "danger" mode you may drop later.

Teach it your own size scale

Your theme adds shadow sizes 100, 200 and 300; you tell tailwind-merge about them so a later shadow replaces an earlier one.

Red border on a form field with an error Idea

A sign-up form swaps the gray border for a red one only while the email is wrong, without both colors fighting.

Clean up style names an AI assistant wrote Idea

Generated components often stack clashing spacing or color names; passing them through the function leaves only the ones that take effect.

Tailwind Merge popularity

80 / 100
Gid Score, #105 overall
118M
downloads a week, npm
5,704
GitHub stars
1,173
agent projects use it
Tailwind Merge: downloads per weeknpm, tailwind-merge 117,711,993
Tailwind Merge: GitHub starsdcastil/tailwind-merge 5,704

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How Tailwind Merge is used

  • Tailwind Merge is a dependency in 1,173 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (24.1% of the 4,867 JavaScript/TypeScript ones), #2 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 4,370; those are left out of every share on this page.
  • Projects that use it most often also use clsx (98.0%), Lucide React (86.6%), Class Variance Authority (85.5%).
  • It is more common in projects set up for Roo Code (29.7%) than for OpenAI Codex (15.8%).

By coding agent

606 projects, 18.5%
593 projects, 24.3%
534 projects, 17.6%
101 projects, 21.3%
74 projects, 15.8%
71 projects, 25.4%
65 projects, 19.0%
33 projects, 29.7%

Often used with

In 98.0% of its projects
In 86.6% of its projects
In 85.5% of its projects
In 98.8% of its projects
In 93.3% of its projects
In 66.4% of its projects
In 63.1% of its projects
In 47.5% of its projects

More about Tailwind Merge

Funding
  • GitHub Sponsors: https://github.com/dcastil
  • 7 GitHub sponsors

See all

More in Styling and CSS

Alternatives

Tailwind Merge This page

MITGid 80118M/wk

clsx

Pick clsx when you only need to switch class names on and off by condition and nothing from outside overrides them.

Class Variance Authority

Pick Class Variance Authority to give a component named variants (primary, danger, small) instead of free-form overrides.

tailwind-variants

Pick tailwind-variants when you want variants and conflict merging in one call for Tailwind components.

Compare Tailwind Merge with another tool

Get started

Tell your AI assistant

“Use the npm package tailwind-merge (pin tailwind-merge@3.7.0, for Tailwind CSS v4) so every component builds its className as twMerge(defaultClasses, props.className), and use twJoin where no override is possible.”

  1. Add the package to your project with the package manager you already use.

    npm add tailwind-merge
    yarn add tailwind-merge
    pnpm add tailwind-merge
    bun add tailwind-merge
    deno add tailwind-merge
    

    From github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/configuration.md

  2. With a standard Tailwind setup, import twMerge and call it with the component's own classes first and the passed-in classes last.

    import { twMerge } from 'tailwind-merge'
    
    twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]')
    // → 'hover:bg-dark-red p-3 bg-[#B91C1C]'
    

    From github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/configuration.md

Mistakes to avoid

Installing tailwind-merge 3.x in a project on Tailwind CSS v3
Check the tailwindcss version first; on v3 pin tailwind-merge@2.6.0, on v4 use 3.x

Version 3.0.0 dropped Tailwind CSS v3 support, changed theme keys and removed the isLength validator.

twMerge('p-2', { 'p-4': isBig })
twMerge(clsx('p-2', { 'p-4': isBig })) or twMerge('p-2', isBig && 'p-4')

twMerge takes strings, arrays and falsy values only; in our run the object was dropped and the result was 'p-2'.

Calling extendTailwindMerge({...}) inside a component or render function
Create the custom function once at module level and import it everywhere

Building the merge function computes a large data structure each time it is called.

Mixing an arbitrary property like [padding:1rem] with p-4 and expecting one to replace the other
Use standard Tailwind classes (p-4 p-8) when they must override each other

Arbitrary properties do not conflict with matching Tailwind classes; our run returned 'p-4 [padding:1rem]'.

font-(--my-family) font-(--my-weight) for a font family set by a variable
font-(family-name:--my-family) font-(--my-weight)

Unlabeled font variables count as font weight, so the family class is removed; our run returned 'font-(--my-weight)'.

Questions

Does the order of the arguments matter?

Yes. When two classes clash, the later one wins, so put the component's own classes first and the passed-in ones last.

Can I pass conditions like with clsx?

Yes for strings, arrays and false, null or undefined values. Objects such as { 'p-4': isBig } are not supported; in our run twMerge ignored the object.

Will calling it on every render slow my app down?

Usually not. Results are cached, up to 500 different results by default.

What if my classes never clash?

Use twJoin from the same package. It only joins strings, which is faster and easier to reason about.

Does it handle hover and other prefixes?

Yes. hover:p-2 and hover:p-4 clash, but p-2 and hover:p-4 are kept together.