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

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

devanoxltd/tailwind-class-merge-laravel
=======================================

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

v1.4.0(2w ago)811MITPHPPHP ^8.4CI passing

Since Jul 26Pushed 1mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (34)Versions (24)Used By (1)

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

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/327e46fed1000936996ce1939a09b1ef9309d303ecf7bbab6b4cb30d557fea89/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d6c61726176656c2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d726f756e642d737175617265)](https://github.com/devanoxltd/tailwind-class-merge-laravel/actions) [![Total Downloads](https://camo.githubusercontent.com/0225c09f746f3ba4a0c2a5ec6d60de1c82b683dcc157e7c8b17cd2815306119e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d6c61726176656c)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-laravel) [![Latest Version](https://camo.githubusercontent.com/eb548b267da3322a10a0fe18e2ba2b99018610480b976b3b70b27494656d1c1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d6c61726176656c)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-laravel) [![License](https://camo.githubusercontent.com/e47b3ef4c4e332a29614c023278a1f785fcefea079702d717ac3c6e3a769f07f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646576616e6f786c74642f7461696c77696e642d636c6173732d6d657267652d6c61726176656c)](https://packagist.org/packages/devanoxltd/tailwind-class-merge-laravel)

---

**TailwindClassMerge for Laravel** 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. This is especially helpful when you want to override Tailwind CSS classes in your Blade components.

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

Supports Tailwind v3.0 up to v3.3.

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

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

> If you are **NOT** using Laravel, you can use the [TailwindClassMerge for PHP](https://github.com/devanoxltd/tailwind-class-merge-php) directly.

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

[](#table-of-contents)

- [Get Started](#get-started)
- [Usage](#usage)
    - [Laravel Blade Components](#use-in-laravel-blade-components)
    - [Laravel Blade Directive](#use-laravel-blade-directive)
    - [Everywhere else in Laravel](#everywhere-else-in-laravel)
- [Configuration](#configuration)
    - [Custom Tailwind Config](#custom-tailwind-config)
- [Contributing](#contributing)

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

[](#get-started)

> **Requires [Laravel 10](https://github.com/laravel/laravel)**

First, install `TailwindClassMerge for Laravel` via the [Composer](https://getcomposer.org/) package manager:

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

Optionally, publish the configuration file:

```
php artisan vendor:publish --provider="TailwindClassMerge\Laravel\TailwindClassMergeServiceProvider"
```

This will create a `config/tailwind-class-merge.php` configuration file in your project, which you can modify to your needs using environment variables. For more information, see the [Configuration](#configuration) section:

```
TAILWIND_MERGE_PREFIX=tw-
```

Finally, you may use `TailwindClassMerge` in various places like your Blade components:

```
// circle.blade.php
tailwindClass('w-10 h-10 rounded-full bg-red-500') }}>

// your-view.blade.php

// output

```

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

```
use TailwindClassMerge\Laravel\Facades\TailwindClassMerge;

// conflicting classes
TailwindClassMerge::merge('block inline'); // inline
TailwindClassMerge::merge('pl-4 px-6'); // px-6

// non-conflicting classes
TailwindClassMerge::merge('text-xl text-black'); // text-xl text-black

// with breakpoints
TailwindClassMerge::merge('h-10 lg:h-12 lg:h-20'); // h-10 lg:h-20

// dark mode
TailwindClassMerge::merge('text-black dark:text-white dark:text-gray-700'); // text-black dark:text-gray-700

// with hover, focus and other states
TailwindClassMerge::merge('hover:block hover:inline'); // hover:inline

// with the important modifier
TailwindClassMerge::merge('!font-medium !font-bold'); // !font-bold

// arbitrary values
TailwindClassMerge::merge('z-10 z-[999]'); // z-[999]

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

// non tailwind classes
TailwindClassMerge::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:

```
TailwindClassMerge::merge('h-10 h-20'); // h-20
TailwindClassMerge::merge(['h-10', 'h-20']); // h-20
TailwindClassMerge::merge(['h-10', 'h-20'], 'h-30'); // h-30
TailwindClassMerge::merge(['h-10', 'h-20'], 'h-30', ['h-40']); // h-40
```

Usage
-----

[](#usage)

For in depth documentation and general PHP examples, take a look at the [devanoxltd/tailwind-class-merge-php](https://github.com/devanoxltd/tailwind-class-merge-php) repository.

### Use in Laravel Blade Components

[](#use-in-laravel-blade-components)

Create your Blade components as you normally would, but instead of specifying the `class` attribute directly, use the `mergeClasses` method:

```
// circle.blade.php
tailwindClass('w-10 h-10 rounded-full bg-red-500') }}>
```

Now you can use your Blade components and pass additional classes to merge:

```
// your-view.blade.php

```

This will render the following HTML:

```

```

> **Note:** Usage of `$attributes->merge(['class' => '...'])` is currently not supported due to limitations in Laravel.

#### Merge classes on multiple elements

[](#merge-classes-on-multiple-elements)

By default Laravel allows you to only merge classes in one place. But with `TailwindClassMerge` you can merge classes on multiple elements by using `forAttributes()`:

```
// button.blade.php
withoutForAttributes()->tailwindClass('p-2 bg-gray-900 text-white') }}>
    forAttributes('icon', 'h-4 text-gray-500') }} viewBox="0 0 448 512">

    {{ $slot }}

```

You can now specify additional classes for the button and the svg icon:

```
// your-view.blade.php

  Click Me

```

This will render the following HTML:

```

  Click Me

```

> Note: Use `withoutForAttributes()` on your main attributes bag, otherwise all `class:xyz` attributes will be rendered in the output.

### Use Laravel Blade Directive

[](#use-laravel-blade-directive)

The package registers a Blade directive which can be used to merge classes in your Blade views:

```
@tailwindClass('w-10 h-10 rounded-full bg-red-500 bg-blue-500') // class="w-10 h-10 rounded-full bg-blue-500"

// or multiple arguments
@tailwindClass('w-10 h-10 rounded-full bg-red-500', 'bg-blue-500') // class="w-10 h-10 rounded-full bg-blue-500"
```

If you want to rename the blade directive, you can do so in the `config/tailwind-class-merge.php` configuration file:

```
// config/tailwind-class-merge.php
return [
    'blade_directive' => 'customTailwindClass',
];
```

You could even disable the directive completely by setting it to `null`:

```
// config/tailwind-class-merge.php
return [
    'blade_directive' => null,
];
```

### Everywhere else in Laravel

[](#everywhere-else-in-laravel)

If you don't use Laravel Blade, you can still use `TailwindClassMerge` by using the Facade or the helper method directly:

#### Facade

[](#facade)

```
use TailwindClassMerge\Laravel\Facades\TailwindClassMerge;

TailwindClassMerge::merge('w-10 h-10 rounded-full bg-red-500 bg-blue-500'); // w-10 h-10 rounded-full bg-blue-500
```

#### Helper Method

[](#helper-method)

```
tailwindClass('w-10 h-10 rounded-full bg-red-500 bg-blue-500'); // w-10 h-10 rounded-full bg-blue-500
```

### More usage examples

[](#more-usage-examples)

Take a look at the [TailwindClassMerge for PHP](https://github.com/devanoxltd/tailwind-class-merge-php) repository.

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.

### Configure Prefix

[](#configure-prefix)

You can configure the prefix directly in the `config/tailwind-class-merge.php` configuration file or by setting the environment variable:

```
TAILWIND_MERGE_PREFIX=tw-
```

### Modify merge process

[](#modify-merge-process)

If TailwindClassMerge is not able to merge your changes properly you can modify the merge process by modifying existing class groups or adding new class groups.

For example, if you want to add a custom font size of "very-large":

```
// config/tailwind-class-merge.php

return [
  'classGroups' => [
      'font-size' => [
          ['text' => ['very-large']]
      ],
  ],
];
```

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

---

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

Credit
------

[](#credit)

This package is fork of [gehrisandro/tailwind-merge-laravel](https://github.com/gehrisandro/tailwind-merge-laravel)

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance92

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

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

Total

23

Last Release

15d ago

Major Versions

v1.0.2 → v2.0.02024-03-28

v2.0.2 → v3.0.02024-04-30

v3.2.0 → v4.0.02024-12-29

v4.0.0 → v5.0.02025-02-20

v5.8.0 → v6.0.02026-03-18

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

v5.2.0PHP ^8.4.0

v5.8.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/79189789?v=4)[Chetan](/maintainers/mrchetan)[@mrchetan](https://github.com/mrchetan)

---

Top Contributors

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

---

Tags

phplaravelmergeclassestailwindcss

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[gehrisandro/tailwind-merge-laravel

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

342974.3k34](/packages/gehrisandro-tailwind-merge-laravel)[gehrisandro/tailwind-merge-php

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

1391.9M13](/packages/gehrisandro-tailwind-merge-php)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4975.8k1](/packages/yieldstudio-tailwind-merge-php)[tales-from-a-dev/tailwind-merge-php

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

14456.0k10](/packages/tales-from-a-dev-tailwind-merge-php)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1422.0k5](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.8k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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