HTML Minifier

Strip the comments and the slack out of your HTML — carefully, leaving alone the places where a space is part of the page. It also gzips both versions, because that is the saving you really get.

Minified


          
—Before
—After
—Saved
—Gzipped before
—Gzipped after

What it removes, and what it will not touch

Comments go. Runs of spaces, tabs and newlines become a single space. Everything inside <pre>, <textarea>, <script> and <style> is left exactly as it was, because in those four a space is content rather than formatting.

The space between tags is not always nothing

This is the mistake that makes minified pages look subtly wrong. Between two inline elements, a space is a word space:

<b>Priya</b> <i>today</i> renders as “Priya today”. Remove that single space and it renders as “Priyatoday”.

So collapsing runs of whitespace down to one space is safe and is what happens by default. Removing that last space entirely is the third tick box, it is off, and it is only safe if you know there are no inline elements sitting next to each other anywhere in the document. Tools that do it without asking are why people stop trusting minifiers.

The number that actually matters

Your server almost certainly sends HTML compressed, and compression is extremely good at exactly the thing minifying removes — repeated spaces and predictable text. So the headline saving is mostly imaginary.

That is why this page gzips both versions and shows you both numbers. It is common to see twenty per cent off the raw file and two or three per cent off the compressed one. Two per cent is still worth having and costs nothing; it is simply not the twenty per cent the first number suggests, and knowing that stops you spending an afternoon on it.

What this is not

It does not rewrite your attributes, drop optional quotation marks, remove closing tags that HTML says are optional, or touch the JavaScript and CSS inside the page. Every one of those saves a little more and every one of them can break something, and a minifier that breaks your page has saved you nothing at all.

Frequently asked questions

Will it break my page?

Not with the default two boxes ticked - those only remove comments and turn runs of whitespace into one space, neither of which changes how a browser renders anything. The third box can change the page, which is why it is off and labelled.

Why is my pre block untouched?

Because every space inside pre, textarea, script and style is content. Collapsing whitespace there would change what the visitor sees or what the code does, so those four are protected and left byte for byte.

Why is the gzipped saving so much smaller?

Because compression already removes most of what minifying removes. Repeated spaces compress to almost nothing. The raw number looks impressive; the gzipped number is what a visitor actually downloads.

Does it minify the CSS and JavaScript inside the page?

No. Those are different languages with different rules, and doing them badly is how minifiers break sites. Use a CSS or JavaScript minifier on those files.

Can I get my original file back?

Not from the output - the removed spaces and comments are gone. Keep your source file and minify as a step when you publish, never in place.

Is my text sent anywhere?

No. Everything happens in JavaScript inside your own browser. Nothing is uploaded and nothing is saved - close the tab and it is gone.

Related tools