HTML Minifier

Remove comments and whitespace from HTML without changing how the page renders.

Paste a page or a fragment.

Conditional comments for old Internet Explorer are always kept.

100 runs left today · sign up for more

About this tool

Removes comments and collapses whitespace in HTML, while leaving alone every place where whitespace is part of what the reader sees.

**This is riskier than minifying CSS, for one reason.** Whitespace between inline elements is rendered. `<a>one</a> <a>two</a>` shows a space between the links; delete it and the words run together. A minifier that strips all whitespace produces a page that is visibly wrong in a way that survives review and is reported by a customer weeks later.

So whitespace is **collapsed to a single space** rather than removed, and it is only removed entirely between block-level tags, where it cannot render. The contents of `pre`, `textarea`, `script` and `style` are left exactly as they are — `pre` is whitespace-significant by definition, and reformatting JavaScript is not this tool's job.

Conditional comments for old Internet Explorer are preserved, because removing them removes a fallback.

Common questions

Why not remove all whitespace?

Because between inline elements it renders as a space. Removing it runs words and links together. The saving from collapsing rather than deleting is a fraction of a per cent, and the failure mode is a visibly broken page.

Is minifying HTML worth doing?

Less than you would think once compression is enabled — gzip handles repeated whitespace extremely well, so most of the saving is already taken. Removing large comment blocks and template debug output is where the real gain is.

Why are conditional comments kept?

They look like comments and are executed by old versions of Internet Explorer. Removing one removes a fallback that was put there deliberately, which is exactly the kind of change a minifier should not make silently.

Should I minify server output on every request?

No. Do it at build time, or not at all. Minifying on every request spends CPU on work whose result is identical each time, and compression is already doing most of what you wanted.