HTML Minifier
Minify HTML online. Remove comments, collapse whitespace and newlines, strip optional tags and attributes, and see exactly how many bytes you saved. Runs in your browser.
Free, no sign-upRuns in your browserNothing uploaded
Collapsing whitespace is unsafe for documents containing inline elements like <span> or <a>: the newline between two tags is a real space, so removing it changes the layout. Optional tag removal is disabled by default for the same reason. If the page has inline markup, use the CSS and JavaScript minifiers on their files instead.
Press Minify to see the result.
- input
- 577 B
- output
- 0 B
- saved
- -
- after gzip (est.)
- -
The estimated compressed figure matters more than the raw one. Gzip and Brotli already squeeze whitespace and repeated tokens, so a 40% raw reduction is usually only a few percent once the file is compressed. Minify anyway, but judge it on the compressed number.
HTML minification removes the parts that cost bytes but change nothing in a browser: comments, indentation, newlines and redundant attribute quotes. On a hand-written or templated page it typically removes 10 to 25% of the file. That matters most before the response is compressed, since Gzip already handles repeated whitespace well - the real benefit is on top of gzip, not instead of it.
The dangerous part of HTML minification is being too aggressive. Removing whitespace between inline elements changes rendering, because HTML collapses a newline between two inline tags into a single space. Removing quotes breaks attribute values containing spaces. Collapsing whitespace inside script, style, pre and textarea does not work at all. Every option here is off unless you turn it on, so the safe subset is the default.
This runs in your browser using html-minifier-terser, the same minifier the terser project maintains for build pipelines, so the output is what you would get from a normal production build. Nothing is uploaded, which means you can minify a template containing proprietary markup without it leaving your machine.
HTML Minifier features
How to use the HTML Minifier
Paste your HTML
Type or paste the markup, or drop an .html file onto the editor.
Enable only what you need
Comment removal, whitespace collapsing and quote removal are the safe defaults. Attribute minimisation, optional tag removal and inline JS/CSS minification are more aggressive - read the notes on each before enabling.
Check the output
Original size, minified size, percentage saved and the character count reduction are shown, along with any warnings about content that was not safe to minify.
Copy or download
Copy the result or download it as a .html file. Always test the minified page in a browser before shipping it.
Frequently asked questions
Is minified HTML harder to debug?
Will minification break my page?
Does minifying actually help load time?
Can I minify JS and CSS inside my HTML?
Why did my comments not all disappear?
Related tools
Every tool, in one place
ToolForge has html minifier plus a growing set of image, colour and developer tools. All of them run locally in your browser, free and without an account.
Browse all tools