PHPackages                             weblabormx/php-remove-unused-css - 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. weblabormx/php-remove-unused-css

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

weblabormx/php-remove-unused-css
================================

PHP Remove Unused CSS is a tool to remove unused CSS from your website using PHP

v1.0.1(2y ago)0163MITPHPPHP &gt;=7.2

Since May 3Pushed 2y agoCompare

[ Source](https://github.com/weblabormx/php-remove-unused-css)[ Packagist](https://packagist.org/packages/weblabormx/php-remove-unused-css)[ Docs](https://github.com/weblabormx/php-remove-unused-css)[ RSS](/packages/weblabormx-php-remove-unused-css/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Overview
--------

[](#overview)

PHP Remove Unused CSS is a tool to remove unused CSS from your website using PHP. Developed by Momentum 81 - .

```
- IMPORTANT! MAKE SURE YOU READ THE GUIDE FIRST OR YOU MAY INADVERTENTLY OVERWRITE YOUR CSS
```

The main idea is to first compile your CSS into as few files as possible, then you would remove the extra classes using this package, then use this (or another) package to minify the CSS.

Often this is done with JS however that can raise issues if you want to work this into a pure PHP development flow.

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

[](#installation)

Installation via composer:

```
composer require momentum81/php-remove-unused-css

```

Example
-------

[](#example)

```
$removeUnusedCss = new \Momentum81\PhpRemoveUnusedCss\RemoveUnusedCssBasic();

$removeUnusedCss->whitelist('.fab', '.far', '.fal')
    ->styleSheets(public_path('**/*.css'))
    ->htmlFiles(resource_path('**/*.blade.php'))
    ->setFilenameSuffix('.refactored.min')
    ->minify()
    ->refactor()
    ->saveFiles();
```

Classes
-------

[](#classes)

The are two main ways of using the package:

- Basic
- Complete (In Development, not yet available)

### Basic Class

[](#basic-class)

The basic class is created using `RemoveUnusedCssBasic`. This is essentially a 'dumb' system that won't traverse the DOM in any way and will just include a selector if it's lowest level appears in the CSS.

That said, this can still provide some significant savings in file size, especially when you're using a package like Bootstrap.

```
$removeUnusedCss = new \Momentum81\PhpRemoveUnusedCss\RemoveUnusedCssBasic();
```

The basic class only weakly matches, lets look at the following HTML:

```

    Hello World

```

The following CSS Classes would match and be kept, despite the `.hello` class being used in the HTML not being inside a parent element using the class `.test`:

```
.test .hello {}
.test .hello::after {}
```

### Complete Class

[](#complete-class)

In Development. This method attempts to be smarter and where possible traverse the DOM as much as it can (When using a templating system this is infinitely more difficult if your views are not cached, so the system can only do so well here).

### Available Methods

[](#available-methods)

MethodDescription`whitelist(...$selectors)`Here you can provice multipleCSS selectors to whitelist, ensuring they remain in the CSS even if they are not present in the HTML.`styleSheets(...$styleSheets)`Here you can provide glob compatible absolute paths to the stylesheets you want to refactor. For example in Laravel, you could use `public_path('**/*.css')`.`htmlFiles(...$htmlFiles)`Here you can provide glob compatible absolute paths to the HTML files (Can be any text file type, not just `.html`) that you want to scan for selectors to keep in your refactored CSS. For example in Laravel, you could use `resource_path('**/*.blade.php')`.`setFilenameSuffix($string)`By default the platform will overwrite the stylesheets it finds (When saving as files), here you can provide a suffix for the file name - this will get appended before the file type. So `stylesheet.css` could become `stylesheet.refactored.min.css`. The default value is `.refactored.min`. IMPORTANT: If you do not specify this method, your original files will be OVERWRITTEN if you use `saveFiles()`!`minify($bool)`If specified, this will perform minification on the CSS before it's saved/returned, using the package `matthiasmullie/minify` ()`skipComment($bool)`Specify if we should skip the comment at the top of the CSS file`comment($string)`Specify custom text for the comment at the top of the CSS file - use the variable `:time:` for the date and time to be added in its place. Don't forget to add your opening and closing tags for the comment: `/* and */`.`refactor()`This method performs the refactoring.`saveFiles()`This will save the new (Or overwritten) files`returnAsText()`This will return the refactored CSS as an array of files with text rather than writing them to real files.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92.3% 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 ~0 days

Total

2

Last Release

743d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13341096?v=4)[Weblabor](/maintainers/weblabormx)[@weblabormx](https://github.com/weblabormx)

---

Top Contributors

[![BenGriffiths](https://avatars.githubusercontent.com/u/1621106?v=4)](https://github.com/BenGriffiths "BenGriffiths (12 commits)")[![skalero01](https://avatars.githubusercontent.com/u/2976641?v=4)](https://github.com/skalero01 "skalero01 (1 commits)")

---

Tags

momentum81php-remove-unused-css

### Embed Badge

![Health badge](/badges/weblabormx-php-remove-unused-css/health.svg)

```
[![Health](https://phpackages.com/badges/weblabormx-php-remove-unused-css/health.svg)](https://phpackages.com/packages/weblabormx-php-remove-unused-css)
```

###  Alternatives

[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[grafite/forms

A remarkably magical form package for Laravel.

376.5k1](/packages/grafite-forms)

PHPackages © 2026

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