PHPackages                             voku/html-min - 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. voku/html-min

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

voku/html-min
=============

HTML Compressor and Minifier

5.0.0(1mo ago)1884.9M↓52.8%24[1 issues](https://github.com/voku/HtmlMin/issues)[2 PRs](https://github.com/voku/HtmlMin/pulls)20MITPHPPHP &gt;=7.1.0CI passing

Since Oct 16Pushed 3w ago9 watchersCompare

[ Source](https://github.com/voku/HtmlMin)[ Packagist](https://packagist.org/packages/voku/html-min)[ Docs](https://github.com/voku/HtmlMin)[ Fund](https://www.paypal.me/moelleken)[ GitHub Sponsors](https://github.com/voku)[ RSS](/packages/voku-html-min/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (5)Versions (98)Used By (20)

[![Build Status](https://github.com/voku/HtmlMin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/voku/HtmlMin/actions)[![Coverage Status](https://camo.githubusercontent.com/43d49cf3a2a8d3bd57e5d455615fedaa70c439808d0b9bbaa3a5b52031f03186/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766f6b752f48746d6c4d696e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/voku/HtmlMin?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/8962af14bd424183b8175d9a2dbdc6821448b08edbe39788e50718d007b8f7a0/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6134333365643262336237353436623361316335323033313032323261363031)](https://www.codacy.com/app/voku/HtmlMin?utm_source=github.com&utm_medium=referral&utm_content=voku/HtmlMin&utm_campaign=Badge_Grade)[![Latest Stable Version](https://camo.githubusercontent.com/fc6bfecd12861b8309d43f136503953ce65ee326f5c6e8abec4e33b00d605829/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d6d696e2f762f737461626c65)](https://packagist.org/packages/voku/html-min)[![Total Downloads](https://camo.githubusercontent.com/f8edbdd1bb017495455f1f43f6d572153d702dd7bb5c7e54aa03784056148349/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d6d696e2f646f776e6c6f616473)](https://packagist.org/packages/voku/html-min)[![License](https://camo.githubusercontent.com/327d8cb4d64f83e7b0efcc10241e375eb236fc6a85248a43d66caaa5babcb224/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f68746d6c2d6d696e2f6c6963656e7365)](https://packagist.org/packages/voku/html-min)[![Donate to this project using Paypal](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.me/moelleken)[![Donate to this project using Patreon](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/voku)

🗜️ HtmlMin: HTML Compressor and Minifier for PHP
================================================

[](#clamp-htmlmin-html-compressor-and-minifier-for-php)

### Description

[](#description)

HtmlMin is a fast and very easy to use PHP library that minifies given HTML5 source by removing extra whitespaces, comments and other unneeded characters without breaking the content structure. As a result pages become smaller in size and load faster. It will also prepare the HTML for better gzip results, by re-ranging (sort alphabetical) attributes and css-class-names.

### Install via "composer require"

[](#install-via-composer-require)

```
composer require voku/html-min
```

### Quick Start

[](#quick-start)

```
use voku\helper\HtmlMin;

$html = "

  \r\n\t

        \xc3\xa0

        \xc3\xa1

  \r\n\t

";
$htmlMin = new HtmlMin();

echo $htmlMin->minify($html);
// ' à  á '
```

### Options

[](#options)

```
use voku\helper\HtmlMin;

$htmlMin = new HtmlMin();

/*
 * Protected HTML (inline css / inline js / conditional comments) are still protected,
 *    no matter what settings you use.
 */

$htmlMin->doOptimizeViaHtmlDomParser();               // optimize html via "HtmlDomParser()"
$htmlMin->doRemoveComments();                         // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveCommentsOnly();                     // remove HTML comments only, without changing any other HTML
$htmlMin->doSumUpWhitespace();                        // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveWhitespaceAroundTags();             // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doOptimizeAttributes();                     // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
$htmlMin->doRemoveHttpPrefixFromAttributes();         // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveHttpsPrefixFromAttributes();        // remove optional "https:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doKeepHttpAndHttpsPrefixOnExternalAttributes(); // keep "http:"- and "https:"-prefix for all external links
$htmlMin->setLocalDomains(['example.com'])->doMakeSameDomainsLinksRelative(); // make some links relative, by removing the domain from attributes
$htmlMin->doRemoveDefaultAttributes();                // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveDeprecatedAnchorName();             // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedScriptCharsetAttribute(); // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromScriptTag();      // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
$htmlMin->doMinifyJavaScript();                       // minify inline JavaScript inside regular  tags (disabled by default)
$htmlMin->doRemoveDeprecatedTypeFromStylesheetLink(); // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDeprecatedTypeFromStyleAndLinkTag(); // remove "type=text/css" from all links and styles
$htmlMin->doRemoveDefaultMediaTypeFromStyleAndLinkTag(); // remove "media="all" from all links and styles
$htmlMin->doRemoveDefaultTypeFromButton();            // remove type="submit" from button tags
$htmlMin->doRemoveEmptyAttributes();                  // remove some empty attributes (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveDataAttributes();                   // remove all "data-*" attributes (depends on "doOptimizeAttributes(true)" | disabled by default)
$htmlMin->doRemoveValueFromEmptyInput();              // remove 'value=""' from empty  (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortCssClassNames();                      // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doSortHtmlAttributes();                     // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
$htmlMin->doRemoveSpacesBetweenTags();                // remove more (aggressive) spaces in the dom (disabled by default)
$htmlMin->doRemoveOmittedQuotes();                    // remove quotes e.g. class="lall" => class=lall
$htmlMin->doRemoveOmittedHtmlTags();                  // apply supported WHATWG optional tag omission rules e.g. lall => lall
```

Current optional tag support from the WHATWG HTML syntax rules:

- ``: start tag may be omitted when the first child is not a comment; end tag may be omitted when the element is not immediately followed by a comment.
- ``: start tag may be omitted when the element is empty or starts with an element; end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.
- ``: start tag may be omitted when the element is empty or starts with something other than ASCII whitespace / a comment / `meta` / `noscript` / `link` / `script` / `style` / `template`; end tag may be omitted when it is not immediately followed by a comment.
- ``: end tag may be omitted before `address`, `article`, `aside`, `blockquote`, `details`, `dialog`, `div`, `dl`, `fieldset`, `figcaption`, `figure`, `footer`, `form`, `h1`-`h6`, `header`, `hgroup`, `hr`, `main`, `menu`, `nav`, `ol`, `p`, `pre`, `search`, `section`, `table`, or `ul`, or at the end of the parent when the parent is not `a`, `audio`, `del`, `ins`, `map`, `noscript`, `video`, or an autonomous custom element.
- ``, ``, ``, ``, ``, ``, ``, and ``: the end tag may be omitted in the standard adjacent-sibling / end-of-parent cases from the spec.
- ``: the end tag may be omitted before another `option`, `optgroup`, or `hr`, or at the end of the parent.
- ``: the end tag may be omitted before another `optgroup` or `hr`, or at the end of the parent.
- ``: the start tag may be omitted when the first child is `col` and the previous omitted-tag rule does not block it; the end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.
- ``: the end tag may be omitted when it is not immediately followed by ASCII whitespace or a comment.
- ``: the end tag may be omitted before `tbody` or `tfoot`.
- ``: the start tag may be omitted when the first child is `tr` and the previous omitted-tag rule does not block it; the end tag may be omitted before `tbody` / `tfoot` or at the end of the parent.
- ``: the end tag may be omitted at the end of the parent.

Start tags are never omitted when the element has attributes.

PS: you can use the "nocompress"-tag to keep the html e.g.: "\\n foobar \\n"

### Unit Test

[](#unit-test)

1. [Composer](https://getcomposer.org) is a prerequisite for running the tests.

```
composer require voku/html-min

```

2. The tests can be executed by running this command from the root directory:

```
./vendor/bin/phpunit
```

### Support

[](#support)

For support and donations please visit [Github](https://github.com/voku/HtmlMin/) | [Issues](https://github.com/voku/HtmlMin/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku).

For status updates and release announcements please visit [Releases](https://github.com/voku/HtmlMin/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts).

For professional support please contact [me](https://about.me/voku).

### Thanks

[](#thanks)

- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [Travis CI](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there!
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerful code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) &amp; [Psalm](https://github.com/vimeo/psalm) for really great Static analysis tools and for discovering bugs in the code!

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance93

Actively maintained with recent releases

Popularity61

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 70.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 ~56 days

Recently: every ~376 days

Total

63

Last Release

47d ago

Major Versions

0.0.7 → 1.0.02016-11-30

1.0.9 → 2.0.02017-12-03

2.0.4 → 3.0.02017-12-22

3.1.8 → 4.0.02019-08-17

4.5.1 → 5.0.02026-04-23

PHP version history (3 changes)0.0.1PHP &gt;=5.3.0

2.0.0PHP &gt;=7.0.0

5.0.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6456fe693db197c458272cb758bf78958bc7d3e787ccd59db4bf3cf41654316a?d=identicon)[voku](/maintainers/voku)

---

Top Contributors

[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (232 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (65 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (9 commits)")[![abuyoyo](https://avatars.githubusercontent.com/u/24979061?v=4)](https://github.com/abuyoyo "abuyoyo (7 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (5 commits)")[![hryvinskyi](https://avatars.githubusercontent.com/u/9294098?v=4)](https://github.com/hryvinskyi "hryvinskyi (3 commits)")[![frugan-dev](https://avatars.githubusercontent.com/u/7957714?v=4)](https://github.com/frugan-dev "frugan-dev (2 commits)")[![tfedor](https://avatars.githubusercontent.com/u/5072842?v=4)](https://github.com/tfedor "tfedor (2 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (1 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (1 commits)")[![tim-kilian](https://avatars.githubusercontent.com/u/5788010?v=4)](https://github.com/tim-kilian "tim-kilian (1 commits)")[![tommyseus](https://avatars.githubusercontent.com/u/637664?v=4)](https://github.com/tommyseus "tommyseus (1 commits)")[![S1SYPHOS](https://avatars.githubusercontent.com/u/12161504?v=4)](https://github.com/S1SYPHOS "S1SYPHOS (1 commits)")

---

Tags

hacktoberfesthtmlhtmlcompressorhtmlminminifiesminifyphpcompressionhtmlminifiercompressorcompress

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/voku-html-min/health.svg)

```
[![Health](https://phpackages.com/badges/voku-html-min/health.svg)](https://phpackages.com/packages/voku-html-min)
```

###  Alternatives

[tubalmartin/cssmin

A PHP port of the YUI CSS compressor

23142.7M63](/packages/tubalmartin-cssmin)[wyrihaximus/html-compress

Compress/minify your HTML

791.7M34](/packages/wyrihaximus-html-compress)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

57133.6k1](/packages/sensiolabs-minify-bundle)[wyrihaximus/minify-html

Html minifier for CakePHP3

18151.2k1](/packages/wyrihaximus-minify-html)[websharks/html-compressor

Combines &amp; compresses CSS/JS/HTML code.

417.1k1](/packages/websharks-html-compressor)[pfaciana/tiny-html-minifier

Minify HTML in PHP with just a single class

10101.8k4](/packages/pfaciana-tiny-html-minifier)

PHPackages © 2026

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