PHPackages                             michtio/tailwind-merge-v3 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. michtio/tailwind-merge-v3

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

michtio/tailwind-merge-v3
=========================

Drop-in fork of gehrisandro/tailwind-merge-php with a widened psr/simple-cache constraint so it can coexist with Craft Commerce (which transitively pins psr/simple-cache ^1.0 via ibericode/vat).

v1.2.0.1(3w ago)01621MITPHPPHP ^8.2.0

Since Jun 16Pushed 3w agoCompare

[ Source](https://github.com/michtio/tailwind-merge-v3)[ Packagist](https://packagist.org/packages/michtio/tailwind-merge-v3)[ GitHub Sponsors](https://github.com/gehrisandro)[ RSS](/packages/michtio-tailwind-merge-v3/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (13)Used By (1)

 [![TailwindMerge for PHP](https://raw.githubusercontent.com/gehrisandro/tailwind-merge-php/main/art/example.png)](https://raw.githubusercontent.com/gehrisandro/tailwind-merge-php/main/art/example.png)

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/b413c5000c9f032a27acb41d21e8d5e2eefadfb776071f6786e58bf4fb0568c2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676568726973616e64726f2f7461696c77696e642d6d657267652d7068702f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d726f756e642d737175617265)](https://github.com/gehrisandro/tailwind-merge-php/actions) [![Total Downloads](https://camo.githubusercontent.com/77390ecd3b16ee057125fe4ec7793f1b2a621f7a852049f3c1293c2e4a44a77b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676568726973616e64726f2f7461696c77696e642d6d657267652d706870)](https://packagist.org/packages/gehrisandro/tailwind-merge-php) [![Latest Version](https://camo.githubusercontent.com/cf3c2f5210fc1ead68ccb6ffe8ed5f5d9163924a17895b3285a0a495cb5bcd29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676568726973616e64726f2f7461696c77696e642d6d657267652d706870)](https://packagist.org/packages/gehrisandro/tailwind-merge-php) [![License](https://camo.githubusercontent.com/0df083fd086fe42aee7f2a79ce9892d0fe625ece7dc5f1a2ad008bf6f25fe010/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676568726973616e64726f2f7461696c77696e642d6d657267652d706870)](https://packagist.org/packages/gehrisandro/tailwind-merge-php)

---

**TailwindMerge for PHP** allows you to merge multiple [Tailwind CSS](https://tailwindcss.com/) classes and automatically resolves conflicts between classes by removing classes conflicting with a class defined later.

A PHP port of [tailwind-merge](https://github.com/dcastil/tailwind-merge) by [dcastil](https://github.com/dcastil).

Supports Tailwind v3.0 up to v3.4.

If you find this package helpful, please consider sponsoring the maintainer:

- Sandro Gehri: **[github.com/sponsors/gehrisandro](https://github.com/sponsors/gehrisandro)**

> If you are using **Laravel**, you can use the [TailwindMerge for Laravel](https://github.com/gehrisandro/tailwind-merge-laravel)

Table of Contents
-----------------

[](#table-of-contents)

- [Get Started](#get-started)
- [Usage](#usage)
- [Cache](#cache)
- [Configuration](#configuration)
- [Contributing](#contributing)

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://php.net/releases/)**

First, install TailwindMerge via the [Composer](https://getcomposer.org/) package manager:

```
composer require gehrisandro/tailwind-merge-php
```

Then, use the `TailwindMerge` class to merge your Tailwind CSS classes:

```
use TailwindMerge\TailwindMerge;

$tw = TailwindMerge::instance();

$tw->merge('text-red-500', 'text-blue-500'); // 'text-blue-500'
```

You can adjust the configuration of `TailwindMerge` by using the factory to create a new instance:

```
use TailwindMerge\TailwindMerge;

$instance = TailwindMerge::factory()
    ->withConfiguration([
        'prefix' => 'tw-',
    ])->make();

$instance->merge('tw-text-red-500', 'tw-text-blue-500'); // 'tw-text-blue-500'
```

For more information on how to configure `TailwindMerge`, see the [Configuration](#configuration) section.

Usage
-----

[](#usage)

`TailwindMerge` is not only capable of resolving conflicts between basic Tailwind CSS classes, but also handles more complex scenarios:

```
use TailwindMerge\TailwindMerge;

$tw = TailwindMerge::instance();

// conflicting classes
$tw->merge('block inline'); // inline
$tw->merge('pl-4 px-6'); // px-6

// non-conflicting classes
$tw->merge('text-xl text-black'); // text-xl text-black

// with breakpoints
$tw->merge('h-10 lg:h-12 lg:h-20'); // h-10 lg:h-20

// dark mode
$tw->merge('text-black dark:text-white dark:text-gray-700'); // text-black dark:text-gray-700

// with hover, focus and other states
$tw->merge('hover:block hover:inline'); // hover:inline

// with the important modifier
$tw->merge('!font-medium !font-bold'); // !font-bold

// arbitrary values
$tw->merge('z-10 z-[999]'); // z-[999]

// arbitrary variants
$tw->merge('[&>*]:underline [&>*]:line-through'); // [&>*]:line-through

// non tailwind classes
$tw->merge('non-tailwind-class block inline'); // non-tailwind-class inline
```

It's possible to pass the classes as a string, an array or a combination of both:

```
$tw->merge('h-10 h-20'); // h-20
$tw->merge(['h-10', 'h-20']); // h-20
$tw->merge(['h-10', 'h-20'], 'h-30'); // h-30
$tw->merge(['h-10', 'h-20'], 'h-30', ['h-40']); // h-40
```

Cache
-----

[](#cache)

For a better performance, `TailwindMerge` can cache the results of the merge operation. To activate pass your cache instance to the `withCache` method.

It accepts any [PSR-16](https://www.php-fig.org/psr/psr-16/) compatible cache implementation.

```
TailwindMerge::factory()
  ->withCache($cache)
  ->make();
```

When you are making changes to the configuration make sure to clear the cache.

Configuration
-------------

[](#configuration)

If you are using Tailwind CSS without any extra config, you can use TailwindMerge right away. And stop reading here.

If you're using a custom Tailwind config, you may need to configure TailwindMerge as well to merge classes properly.

By default TailwindMerge is configured in a way that you can still use it if all the following apply to your Tailwind config:

- Only using color names which don't clash with other Tailwind class names
- Only deviating by number values from number-based Tailwind classes
- Only using font-family classes which don't clash with default font-weight classes
- Sticking to default Tailwind config for everything else

If some of these points don't apply to you, you need to customize the configuration.

This is an example to add a custom font size of "very-large":

```
TailwindMerge::factory()->withConfiguration([
        'classGroups' => [
            'font-size' => [
                ['text' => ['very-large']]
            ],
        ],
    ])->make();
```

For a more detailed explanation of the configuration options, visit the [original package documentation](https://github.com/dcastil/tailwind-merge/blob/v1.14.0/docs/configuration.md).

Contributing
------------

[](#contributing)

Thank you for considering contributing to `TailwindMerge for PHP`! The contribution guide can be found in the [CONTRIBUTING.md](CONTRIBUTING.md) file.

---

TailwindMerge for PHP is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 95.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~176 days

Recently: every ~213 days

Total

7

Last Release

27d ago

Major Versions

v0.0.1 → v1.0.02023-10-18

PHP version history (2 changes)v0.0.1PHP ^8.1.0

v1.2.0PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c7d5b4ecc0f3577f5a56f8411148e5d35d76e31593ff8529146acae89c5ad321?d=identicon)[michtio](/maintainers/michtio)

---

Top Contributors

[![gehrisandro](https://avatars.githubusercontent.com/u/25097194?v=4)](https://github.com/gehrisandro "gehrisandro (47 commits)")[![mr-chetan](https://avatars.githubusercontent.com/u/56998650?v=4)](https://github.com/mr-chetan "mr-chetan (1 commits)")[![WebMamba](https://avatars.githubusercontent.com/u/32077734?v=4)](https://github.com/WebMamba "WebMamba (1 commits)")

---

Tags

phpmergeclassestailwindcss

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/michtio-tailwind-merge-v3/health.svg)

```
[![Health](https://phpackages.com/badges/michtio-tailwind-merge-v3/health.svg)](https://phpackages.com/packages/michtio-tailwind-merge-v3)
```

###  Alternatives

[gehrisandro/tailwind-merge-php

TailwindMerge for PHP merges multiple Tailwind CSS classes by automatically resolving conflicts between them

1391.7M12](/packages/gehrisandro-tailwind-merge-php)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

340790.3k27](/packages/gehrisandro-tailwind-merge-laravel)[tales-from-a-dev/tailwind-merge-php

TailwindMerge for PHP merges multiple Tailwind CSS classes by automatically resolving conflicts between them

11312.6k9](/packages/tales-from-a-dev-tailwind-merge-php)[florianv/exchanger

PHP exchange rate provider layer for currency conversion: 30 services, chain fallback, and caching.

1854.9M19](/packages/florianv-exchanger)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4974.6k1](/packages/yieldstudio-tailwind-merge-php)[tailwindphp/tailwindphp

A full port of TailwindCSS 4.x to PHP

192.5k3](/packages/tailwindphp-tailwindphp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
