How to use HTML Minifier
- Paste your HTML.
- Read the minified output and the size saved.
- Check inline elements and any pre or textarea content before using it.
- Whitespace between inline elements is significant — removing it joins words together.
- Content in pre and textarea must be preserved exactly.
- Keep minification in your build; do not commit minified HTML as source.
HTML whitespace is not always insignificant
Unlike JSON, HTML has places where whitespace matters. A space between two inline elements is a real space in the rendered output, so removing it runs words together — <b>one</b> <i>two</i> becomes “onetwo”. Content inside <pre> and <textarea> is preserved verbatim and must not be touched at all. Elements with white-space: pre in CSS have the same constraint, which a minifier cannot see because it does not read your stylesheet. This is why aggressive HTML minification occasionally produces visible layout bugs where JavaScript minification does not.
The savings are smaller than they look
Removing whitespace from a typical HTML document saves 10–20% of the raw bytes, and most of that is recovered by gzip or Brotli anyway, since repeated indentation compresses extremely well. The real page-weight wins are elsewhere: images, which are usually the bulk of a page; JavaScript, which costs parse and execution time as well as bytes; and web fonts. Minifying HTML is worth doing in a build because it is free, and it is not where a slow page gets fixed.
Do it in the build, never by hand
Minified HTML is unreadable and undiffable, so it should be a build output rather than something you commit. Every static site generator and bundler does it, as do most CDNs at the edge. If you are minifying by hand and pasting the result back into your source, you have made the file permanently harder to maintain to save bytes that compression was already handling.
Frequently asked questions
What does HTML minification remove?
How much file size reduction can I expect?
Is minified HTML still valid?
How much smaller does minifying HTML make a page?
Can minifying HTML break my page?
Should I minify HTML if my server uses compression?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.