Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

HtmlMin

> 前端框架
Open source

:clamp: HtmlMin: HTML Compressor and Minifier via PHP

182 stars0 likes1 views
WebsiteGitHub

About

:clamp: HtmlMin: HTML Compressor and Minifier via PHP

:clamp: HtmlMin: HTML Compressor and Minifier for PHP

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"

bash
composer require voku/html-min

Quick Start

php
use voku\helper\HtmlMin;

$html = "

  \r\n\t
  
    

      

        \xc3\xa0
      

      

        \xc3\xa1
      

    

  
  \r\n\t

";
$htmlMin = new HtmlMin();

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

 à 
 á 
'

Options

…

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

  1. Composer is a prerequisite for running the tests.
composer require voku/html-min
  1. The tests can be executed by running this command from the root directory:
bash
./vendor/bin/phpunit

Support

For support and donations please visit Github | Issues | PayPal | Patreon.

For status updates and release announcements please visit Releases | Twitter | Patreon.

For professional support please contact me.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerful code style check.
  • Thanks to PHPStan & Psalm for really great Static analysis tools and for discovering bugs in the code!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPhacktoberfesthtmlhtmlcompressorhtmlmin

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架