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

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

devanoxltd/tailwind-class-merge-php
===================================

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

v4.0.0(1mo ago)12605↓100%MITPHPPHP ^8.4CI passing

Since Jan 10Pushed 1mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (15)Used By (0)

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

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/301224a4c7e13686e45e04fc1a3022989367794e26c5722333af829d096050fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d7068702f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d726f756e642d737175617265)](https://github.com/devanoxltd/tailwind-class-merge-php/actions) [![Total Downloads](https://camo.githubusercontent.com/03dfb9a1d6ce4aed5ae381abd9a36b29a84be5acb9db9b62f1ccbe6acf2424a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d706870)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-php) [![Latest Version](https://camo.githubusercontent.com/0d320f7930e88b94678e6702d77175f9ae9c790f46ec73842f7dd742a1fba355/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d706870)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-php) [![License](https://camo.githubusercontent.com/879bdc2a61baa4c44a8ce42ccaa4459d834ad77f2e0c9b9739a93a5689886635/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d706870)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-php)

---

**TailwindClassMerge 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). And clone and improve from [tailwind-merge-php](https://github.com/gehrisandro/tailwind-merge-php) by [gehrisandro](https://github.com/gehrisandro).

Supports Tailwind v3.0 up to v3.4.

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

- Devanox Private Limited: **[github.com/sponsors/devanoxltd](https://github.com/sponsors/devanoxltd)**

> **Attention:** This package is still in early development.

> If you are using **Laravel**, you can use the [TailwindClassMerge for Laravel](https://github.com/devanoxltd/tailwind-class-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 TailwindClassMerge via the [Composer](https://getcomposer.org/) package manager:

```
composer require devanoxltd/tailwind-class-merge-php
```

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

```
use TailwindClassMerge\TailwindClassMerge;

$tw = TailwindClassMerge::instance();

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

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

```
use TailwindClassMerge\TailwindClassMerge;

$instance = TailwindClassMerge::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 `TailwindClassMerge`, see the [Configuration](#configuration) section.

Usage
-----

[](#usage)

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

```
use TailwindClassMerge\TailwindClassMerge;

$tw = TailwindClassMerge::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, `TailwindClassMerge` 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.

```
TailwindClassMerge::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 TailwindClassMerge right away. And stop reading here.

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

By default TailwindClassMerge 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":

```
TailwindClassMerge::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 `TailwindClassMerge for PHP`! The contribution guide can be found in the [CONTRIBUTING.md](CONTRIBUTING.md) file.

---

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

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance90

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~61 days

Recently: every ~98 days

Total

14

Last Release

52d ago

Major Versions

v1.1.1 → v2.0.02024-03-28

v2.3.0 → v3.0.02025-02-20

v3.3.0 → v4.0.02026-03-18

PHP version history (3 changes)v1.0.0PHP ^8.2.0

v3.1.0PHP ^8.3.0

v3.3.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5039d3102378ab6c20d60bf6fe8e864b7ee984e6a96c6f0cfcb48bc070574cf8?d=identicon)[mrchetan](/maintainers/mrchetan)

---

Top Contributors

[![mr-chetan](https://avatars.githubusercontent.com/u/56998650?v=4)](https://github.com/mr-chetan "mr-chetan (50 commits)")

---

Tags

phputilitycssclasstailwindmergeclassesutilitiestailwindcssdevanoxltddevanox

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devanoxltd-tailwind-class-merge-php/health.svg)

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

###  Alternatives

[gehrisandro/tailwind-merge-php

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

1391.5M9](/packages/gehrisandro-tailwind-merge-php)[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)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

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

A full port of TailwindCSS 4.x to PHP

171.7k1](/packages/tailwindphp-tailwindphp)[nlac/nlsclientscript

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

208.2k](/packages/nlac-nlsclientscript)[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)
