Compress HTML by removing comments and whitespace that renders as nothing, while keeping the space between inline elements that is visible on the page.
Waiting for markup
Only whitespace that renders as nothing is removed. Scripts, styles and <pre> are left exactly as written.
Minified markup appears here
Whitespace between block elements goes; a space between inline elements stays, because it is a real space on the page.
HTML Minifier runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
The one-line HTML minifier everyone writes is source.replace(/>\s+</g, "><"), and it is wrong in three ways that show up on real pages. It eats the space between </b> and <i>, which is a visible space in the rendered text. It destroys the contents of <pre>, where whitespace is the entire point. And it mangles any script containing a > followed by a <, which includes most comparisons.
This one reads the document with a tokenizer first, so it knows which whitespace renders as nothing and which does not. Whitespace between two block-level boundaries is removed, because the browser collapses it to nothing anyway. Whitespace between inline content becomes a single space, because that is what the browser renders. Inside pre, textarea, script and style, nothing is touched.
It is deliberately conservative about everything else. It does not minify the JavaScript or CSS it finds inside the document, because that needs a parser for those languages. It does not remove the optional closing tags HTML lets you omit — and it does not add them either, which a tree-based minifier would, making the output larger than the input. It does not drop attributes it believes are defaults.
Attribute quotes are the one optional transformation, and it is off by default. HTML permits an unquoted attribute value when it contains no whitespace, quotes, equals sign or angle bracket, and the tool checks all four before dropping them. The result is valid and a few bytes smaller, and it is more fragile for anything that later edits the HTML by hand.
Realistically, gzip or brotli on your server will do more for transfer size than any of this. Minification helps most when the HTML is being embedded somewhere that is not compressed — an email, a data attribute, a string literal in code.
It should not. Only whitespace that the browser renders as nothing is removed, and a space between inline elements — which is visible — is always kept as one space. If something does change, the usual cause is CSS that depended on whitespace the browser was already collapsing.
No. Script and style bodies are reproduced exactly as written. Minifying either properly needs a parser for that language, and a regular-expression pass over JavaScript is how working code silently breaks.
Because that whitespace is the content. Everything inside pre and textarea is reproduced byte for byte, as is everything inside script and style.
Probably not. The saving is a couple of bytes per attribute, and the result is more fragile for anything that later edits the HTML with a regular expression or by hand. It is off by default for that reason, and quotes are only dropped where HTML genuinely permits it.
No, and gzip will almost certainly save you more. Minification is most useful where compression is not available — HTML embedded in an email, in a string literal, or in a data attribute.
That is unusual and generally means the input was already minified with a tool that removed optional closing tags. This tool never adds those back, so check the byte counts under the result — they show exactly what happened.