Overview
Introduction
A hand-authored HTML page carries a lot of whitespace and comments that add up over many requests.
This tool minifies HTML using html-minifier-terser, entirely in your browser, including any embedded CSS and JavaScript.
What Is HTML Minifier?
A minifier that collapses whitespace between tags, removes comments and empty attributes, and minifies embedded `<style>` and `<script>` content.
The page renders identically; only its size and source readability change.
How HTML Minifier Works
The document is parsed and whitespace-insensitive regions are collapsed, while whitespace-sensitive elements like `<pre>` are left untouched.
Embedded CSS and JS blocks are passed through the same minifiers used by the CSS and JavaScript minifier tools.
When To Use HTML Minifier
Use it before shipping a static HTML page that isn't already processed by a build tool.
It's also useful for shrinking an HTML email template or an inline snippet, where a build pipeline isn't practical.
Often used alongside HTML Formatter, HTML Validator and CSS Minifier.
Features
Advantages
- Runs entirely client-side.
- Minifies embedded CSS and JS alongside the markup, not just the tags.
- Strips comments and empty attributes automatically, cleanup that's tedious to do by hand across a large page.
Limitations
- Whitespace-sensitive elements like `<pre>` are preserved rather than collapsed, which is intentional.
Examples
Best Practices & Notes
Best Practices
- Check the size savings panel, especially for pages with a lot of embedded inline CSS or JS.
- Run the HTML Validator first if the page has any unusual markup, since a malformed document can confuse the minifier's parser.
Developer Notes
Uses `html-minifier-terser`'s `minify()` with `collapseWhitespace`, `removeComments`, `minifyCSS`, and `minifyJS` enabled, dynamically imported to keep it out of other tools' bundles.
HTML Minifier Use Cases
- Shrinking a static HTML page before deployment
- Comparing minified vs. unminified page size
Common Mistakes
- Editing minified HTML output directly instead of the original source.
- Assuming comments are always safe to strip; removeComments removes all of them indiscriminately, including any a build process or other tooling relies on.
Tips
- If minification fails, run the HTML Validator first to confirm the markup is well-formed.
- If the size savings look small, check whether the page was already terse markup with little embedded CSS or JS to shrink.