Minify HTML with compression options. Part of the DevTools Surf developer suite. Browse more tools in the HTML collection.
Use Cases
Reduce HTML payload size for email templates where download speed affects open rates on mobile.
Minify server-rendered pages before caching in a CDN to reduce egress bandwidth costs.
Strip development comments from production HTML before deployment.
Compress static HTML files as part of a site generator build pipeline.
Tips
Enable 'remove comments' and 'collapse whitespace' as a baseline — these two options alone typically reduce HTML size by 15-30%.
Be cautious with 'remove optional tags' — omitting </li> or </td> closing tags is valid HTML5 but can confuse some parsers and older templating engines.
Minify HTML as the last build step, after all templating and component rendering is complete, to avoid mangling template syntax.
Fun Facts
HTML whitespace collapse was specified in the CSS 2.1 spec (2006) — adjacent whitespace characters in HTML are rendered as a single space, making all internal whitespace between tags safe to remove.
Google's PageSpeed study (2018) found that reducing HTML payload by 100KB improved Time to First Byte by 8ms on median mobile connections — meaningful at scale for high-traffic pages.
The HTML5 specification formally documents which end tags are optional: </html>, </head>, </body>, </li>, </dt>, </dd>, </p>, </td>, </th>, and </tr> can all be legally omitted.
FAQ
Is minified HTML still valid?
Yes — all minification options produce spec-valid HTML5. Optional-tag removal is the most aggressive option; conservative mode preserves all tags while still collapsing whitespace and removing comments.
Does it minify inline CSS and JS?
Yes — inline <style> blocks are passed through a CSS minifier and inline <script> blocks through a JS minifier. External files referenced by src/href are not touched.
How much size reduction can I expect?
Typical results: 15-30% for content-heavy pages, 5-15% for heavily-templated apps where most markup is already compact. Minification compounds with gzip, which reduces already-minified text further.