ποΈ Free HTML Minifier
Compress HTML for production. Comments and whitespace removed safely, with pre, script, and style contents protected.
How to Use This HTML Minifier
Paste your HTML into the input box and the minified version appears instantly. Toggle the two options to control exactly what gets removed.
Paste your full HTML document into the Input HTML box. The output updates live as you type or paste.
Choose your options. "Remove comments" strips regular HTML comments; "Collapse whitespace" removes newlines, indentation, and the gaps between tags.
Check the byte counts and savings percentage below the boxes to see exactly how much smaller the file got.
Copy the output or download it as a .html file, then deploy it to your server or paste it where you need compact HTML.
How Safe Minification Works
Naive minifiers break pages because not all whitespace is equal. The four dangerous cases are handled first: the tool extracts every pre, textarea, script, and style block and replaces it with a placeholder before doing anything else. Comments are removed only from what remains, and conditional comments such as [if lt IE 9] are always kept because they carry real behavior. Then whitespace is collapsed: newlines and indentation disappear, and the gaps between a closing and opening tag (><) are removed. Inside the protected blocks nothing changes at all, so code samples in pre tags keep their formatting, textarea default text stays intact, and embedded JavaScript and CSS are never touched. Finally the placeholders are swapped back for the original blocks, in order. That is why you can run a full page through this tool and the rendered result is identical: it only removes bytes the browser would have ignored anyway.
Worked Example
Input this small document (93 bytes):
<div> <!-- header comment --> <p>Hello world</p> <pre> keep spacing </pre> </div>The minifier removes the comment, collapses the runs of spaces inside the paragraph to single spaces, and joins the tags. The pre block is restored exactly as written, spaces and all. The output is 57 bytes: a savings of 39 percent, with the rendered page unchanged.
When to Minify (and When Not To)
Frequently Asked Questions
What does an HTML minifier do?
It shrinks an HTML document by removing things the browser does not need: comments, extra whitespace, newlines, and spaces between tags. The visible page renders exactly the same, but the file is smaller and downloads faster.
Is minified HTML still valid?
Yes. Minification only removes optional whitespace and comments, which HTML parsers ignore. The structure of the document does not change, so a minified page validates the same way the original did.
Why does this minifier protect pre, script, and style blocks?
Whitespace inside pre and textarea is meaningful: it is rendered as-is on the page, so collapsing it would change what visitors see. Script and style contents are code, where removing whitespace or comments can break JavaScript strings or CSS. This tool extracts those blocks before minifying and restores them untouched.
Are conditional comments removed?
No. Internet Explorer conditional comments like [if lt IE 9] are kept on purpose, since removing them could change behavior for the browsers they target. Only regular HTML comments are removed.
How much can HTML minification save?
It depends on how the HTML was written. Hand-formatted documents with heavy indentation and many comments typically shrink 10 to 30 percent. Machine-generated HTML that is already compact saves less. Run your own file through the tool to see the exact number.