PHPackages                             gehrisandro/tailwind-merge-php - 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. gehrisandro/tailwind-merge-php

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

gehrisandro/tailwind-merge-php
==============================

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

v1.2.0(1mo ago)1391.5M—4.8%6[3 issues](https://github.com/gehrisandro/tailwind-merge-php/issues)[3 PRs](https://github.com/gehrisandro/tailwind-merge-php/pulls)8MITPHPPHP ^8.2.0CI passing

Since Jun 16Pushed 1mo ago5 watchersCompare

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

READMEChangelog (5)Dependencies (18)Versions (11)Used By (8)

 [![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

61

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity56

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity63

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 ~201 days

Recently: every ~221 days

Total

6

Last Release

59d 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/6180f55dc35aac59961f36ce372004c3d00c7447c9e9a4b78e8eff6d8e3b0840?d=identicon)[gehrisandro](/maintainers/gehrisandro)

---

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/gehrisandro-tailwind-merge-php/health.svg)

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

###  Alternatives

[gehrisandro/tailwind-merge-laravel

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

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nlac/nlsclientscript

Yii ClientScript extension for prevent reloading javascript and merging/minfying resources

208.2k](/packages/nlac-nlsclientscript)[tailwindphp/tailwindphp

A full port of TailwindCSS 4.x to PHP

171.7k1](/packages/tailwindphp-tailwindphp)[arnolem/tailwindphp

TailwindPHP - use Tailwind CSS in your PHP projects (without npm)

131.1k](/packages/arnolem-tailwindphp)

PHPackages © 2026

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