Free Online HTML Minifier
The HTML Minifier removes comments and collapses whitespace between tags to shrink your markup. Content inside pre, textarea, script, and style elements is preserved exactly.
Minification is the last step before deployment, so the result is worth checking with the HTML Formatter & Beautifier and the Broken Link Checker List. The CSS and script assets alongside it are handled by the CSS Minifier and JavaScript Minifier.
How to use the HTML Minifier
- 1 Paste your HTML, or load a file.
- 2 Choose how aggressive to be: whitespace-only, or whitespace plus optional tag and attribute removal.
- 3 Check the reported size saving before you commit.
- 4 Copy the minified output, and test the page afterwards — minification can expose a bug in sloppy markup.
What is worth doing instead
The real wins in page weight come from elsewhere: fewer and smaller images, less client-side JavaScript, and eliminating render-blocking resources. HTML minification typically saves a few per cent before compression and a fraction of that after it.
That is not to say it is pointless. Removing comments matters if they contain internal notes you would rather not publish, and stripping optional closing tags produces a slightly smaller parse tree. Just do not expect it to move a performance metric.
- Whitespace and comments go first; both are safe.
- Optional closing tags are safe in HTML5 but not in XHTML.
- Whitespace between inline elements is the real hazard.
- Compare against gzip — the compressed saving is usually tiny.
Frequently asked questions
What does HTML minification actually remove?
Whitespace between block elements, comments, and optionally redundant attributes such as a `type="text/javascript"` on a script tag or a default `type` on a stylesheet link. It may also remove optional closing tags, since HTML allows certain elements to omit them. None of it changes what the document means.
Why did my layout break after minifying?
Because whitespace between inline elements is significant. Minification collapses the space between, say, two `<span>` elements or between two inline images, and if the layout relied on that space to separate them they will jump together. This is the one genuine hazard, and it only affects inline content.
Does minifying HTML worthwhile compared with gzip?
Far less than people expect, because a web server already compresses HTML on the wire and gzip removes most of what minification would. The redundancy minification targets — repeated tag names, consistent indentation — is exactly what a compression algorithm is good at. Minify for tidiness or if you are serving uncompressed, not as a size strategy on its own.
Related Developer Tools
You might also need
Tools from other categories that people pair with the HTML Minifier: