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.md3. Used by agents' projects
Dependency in 1,173 public GitHub projects set up for AI coding agents that we scanned (18.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
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
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
Often used with
More about Tailwind Merge
Funding
- GitHub Sponsors: https://github.com/dcastil
- 7 GitHub sponsors
Alternatives
Tailwind Merge This page
Pick clsx when you only need to switch class names on and off by condition and nothing from outside overrides them.
Pick Class Variance Authority to give a component named variants (primary, danger, small) instead of free-form overrides.
Pick tailwind-variants when you want variants and conflict merging in one call for Tailwind components.
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.”
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-mergeWith 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]'
Mistakes to avoid
Version 3.0.0 dropped Tailwind CSS v3 support, changed theme keys and removed the isLength validator.
twMerge takes strings, arrays and falsy values only; in our run the object was dropped and the result was 'p-2'.
Building the merge function computes a large data structure each time it is called.
Arbitrary properties do not conflict with matching Tailwind classes; our run returned 'p-4 [padding:1rem]'.
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.