abordage / html-min
Very simple (and very fast) PHP package for HTML minification
Installs: 87 703
Dependents: 2
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/abordage/html-min
Requires
- php: >=7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.5
- dev-master
- 1.0.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-7
- dev-dependabot/github_actions/dependabot/fetch-metadata-2.4.0
- dev-dependabot/github_actions/actions/checkout-6
- dev-feature/remove-trailing-slashes
- dev-dependabot/github_actions/lycheeverse/lychee-action-2.2.0
This package is auto-updated.
Last update: 2026-01-05 08:57:43 UTC
README
HtmlMin: PHP package for HTML minification
Very simple (and very fast) html compression. See benchmark and comparison
Features
- Removing extra whitespaces
- Removing html comments
- Removing trailing slashes from void elements (HTML5)
- Skip
textarea,preandscriptelements - Compresses in microseconds. See benchmark and comparison
Requirements
- PHP 7.4 or higher
Installation
You can install the package via composer:
composer require abordage/html-min
Quick start
<?php require __DIR__ . '/vendor/autoload.php'; $htmlMin = new Abordage\HtmlMin\HtmlMin(); $result = $htmlMin->minify("<!DOCTYPE html><html> ... </html>");
Options
$htmlMin->findDoctypeInDocument(); // default: true $htmlMin->removeWhitespaceBetweenTags(); // default: true $htmlMin->removeBlankLinesInScriptElements(); // default: false $htmlMin->removeTrailingSlashes(); // default: false
Remove trailing slashes
In HTML5, void elements (<link>, <meta>, <img>, <br>, etc.) should not have trailing slashes.
Enable this option to convert XHTML-style tags like <link ... /> to HTML5-style <link ...>.
$htmlMin->removeTrailingSlashes(); $result = $htmlMin->minify('<link rel="stylesheet" href="style.css" />'); // Result: <link rel="stylesheet" href="style.css">
Benchmark
See abordage/html-min-benchmark
Testing
composer test:all
or
composer test:phpunit composer test:phpstan composer test:phpcsf
or see https://github.com/abordage/html-min/actions/workflows/tests.yml
Feedback
If you have any feedback, comments or suggestions, please feel free to open an issue within this repository.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
