# Tailwind Merge — card for AI agents

Merge Tailwind CSS classes intelligently without style conflicts.

Category: Styling and CSS · npm package `tailwind-merge` · latest version 3.7.0 (checked 2026-11-01)
Install: `npm install tailwind-merge`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 79.9 (#105 of all tools, 2 of 53 in its category)
- Used in 1,173 public projects set up for AI coding agents (18.7%)
- Downloads last week: 117,711,993 (as of 2026-11-24), +30.0% over 4 weeks
- GitHub stars: 5,704 (as of 2026-11-24)
- Last push: 2026-11-22

## Often used with
clsx 98.0%, Lucide React 86.6%, Class Variance Authority 85.5%, Tailwind CSS 98.8%, React 93.3%, Radix UI 66.4%

## Links
- AgentGid page: https://agentgid.com/tools/tailwind-merge/
- Homepage: https://github.com/dcastil/tailwind-merge
- Repository: https://github.com/dcastil/tailwind-merge


## tailwind-merge: let the last Tailwind style win

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.

### Where to use 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: A sign-up form swaps the gray border for a red one only while the email is wrong, without both colors fighting. (idea, not from the official pages)
- Clean up style names an AI assistant wrote: Generated components often stack clashing spacing or color names; passing them through the function leaves only the ones that take effect. (idea, not from the official pages)

### How to start
- 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
```

- 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]'
```


### License
Free to use, change and sell as part of your product under the MIT license. Keep its copyright and license notice in copies of the package you ship.

### Good to know
- Version 3 works with Tailwind CSS 4.0 to 4.3 only. A project still on Tailwind 3 needs tailwind-merge 2.6.0.
- It adds about 7 kB to the page, mostly a built-in list of which Tailwind names clash.
- It does not read your own style sheet. A custom name that sets padding is kept next to Tailwind padding names.
- Custom names that look like Tailwind ones, such as text-2xs, are treated as Tailwind and can remove a real size name.
- The docs call it an escape hatch; letting every user restyle a component makes it harder to change that component later.

Checked 2026-11-11 against: https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/README.md, https://github.com/dcastil/tailwind-merge/blob/main/LICENSE.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/what-is-it-for.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/when-and-how-to-use-it.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/features.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/limitations.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/configuration.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/recipes.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/api-reference.md, https://github.com/dcastil/tailwind-merge/blob/tailwind-merge@3.7.0/packages/tailwind-merge/docs/versioning.md, https://github.com/dcastil/tailwind-merge/releases/tag/v3.0.0, https://registry.npmjs.org/tailwind-merge/latest

### Mistakes to avoid
- Don't: Installing tailwind-merge 3.x in a project on Tailwind CSS v3 → Do: 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.)
- Don't: twMerge('p-2', { 'p-4': isBig }) → Do: 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'.)
- Don't: Calling extendTailwindMerge({...}) inside a component or render function → Do: 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.)
- Don't: Mixing an arbitrary property like [padding:1rem] with p-4 and expecting one to replace the other → Do: 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]'.)
- Don't: font-(--my-family) font-(--my-weight) for a font family set by a variable → Do: 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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
