PHPackages                             baethon/tailwind-class-collapse - 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. baethon/tailwind-class-collapse

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

baethon/tailwind-class-collapse
===============================

Collapse list of Tailwind CSS classes

v1.0.0(6y ago)1121[1 PRs](https://github.com/baethon/tailwind-class-collapse/pulls)MITPHPPHP &gt;=7.4CI failing

Since Mar 13Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/baethon/tailwind-class-collapse)[ Packagist](https://packagist.org/packages/baethon/tailwind-class-collapse)[ RSS](/packages/baethon-tailwind-class-collapse/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/55cedd2e477350014ec231b446c424c49acfe91c94b9fd3f76054abc5090c9b9/68747470733a2f2f7472617669732d63692e6f72672f62616574686f6e2f7461696c77696e642d636c6173732d636f6c6c617073652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/baethon/tailwind-class-collapse)

---

baethon/tailwind-class-collapse
===============================

[](#baethontailwind-class-collapse)

Removes Tailwind class names keeping the rightmost class of the same type.

Installation
------------

[](#installation)

```
composer require baethon/tailwind-class-collapse

```

Usage
-----

[](#usage)

```
use function Baethon\Tailwind\class_collapse as tailwind_class_collapse;

$class = tailwind_class_collapse('shadow font-bold text-gray-700 py-2 px-4 rounded text-center inline-block focus:shadow-outline focus:outline-none bg-blue-500 text-white hover:bg-blue-400');

// shadow font-bold py-2 px-4 rounded text-center inline-block focus:shadow-outline focus:outline-none bg-blue-500 text-white hover:bg-blue-400
```

Why collapse?
-------------

[](#why-collapse)

I'll use an example. Consider following [snippet](https://codepen.io/radmen/pen/WNvzdYB):

```
Sign In
```

As you can see, the `text-white` did not apply correctly. It's overwritten by the `text-gray-700`. To fix this, you need to remove the `text-gray-700` class.

Easy right? Well, things get complicated when you have a solution which appends some classes based on a set of predicates. To avoid the issue one should set condition statements making simple things complex.

How does it work?
-----------------

[](#how-does-it-work)

`class_collapse()` groups Tailwind classes by their purpose (or, in most cases, by the CSS property they set). It splits the class list by space and preserves only the rightmost class of the same type. The package supports Tailwinds [pseudo-class variants](https://tailwindcss.com/docs/pseudo-class-variants).

Supported Tailwind versions
---------------------------

[](#supported-tailwind-versions)

For now, the package supports only Tailwind v1.2. It's possible to add class definitions for other versions, however I don't intend doing this now. If you'd like to add support for different Tailwind version feel free to open a PR.

Testing
-------

[](#testing)

```
composer test

```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance53

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% 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

Unknown

Total

1

Last Release

2256d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/488bdbbb3187d1f4f6d9c92f0c716ad413f5e7fe53d3ec5ffefb37cfcad4ecf6?d=identicon)[radmen](/maintainers/radmen)

---

Top Contributors

[![radmen](https://avatars.githubusercontent.com/u/1190255?v=4)](https://github.com/radmen "radmen (23 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/baethon-tailwind-class-collapse/health.svg)

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

###  Alternatives

[carlcs/craft-deleteentryversions

Delete Entry Versions plugin for Craft CMS

2613.6k](/packages/carlcs-craft-deleteentryversions)[crisen/ai

优雅的ai客户端

265.5k1](/packages/crisen-ai)

PHPackages © 2026

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