Skip to content
ToolForge
Developer Tools

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

Safe options by default
Comments and collapsible whitespace are removed; nothing risky is enabled unless you ask for it.
Whitespace safety checks
Warns about removed whitespace between inline elements and refuses to collapse inside script, style, pre and textarea.
Optional tag and attribute removal
Strip closing tags the HTML5 parser can infer and redundant attributes, with each one labelled by its risk.
Inline minification
Optionally minify embedded script and style blocks too, using the same engine as the standalone tools.
Byte savings report
Before and after sizes, percentage saved and absolute reduction, so you can tell whether minification was worth the build step.
Diff-sized readout
Character count and line count, since a minified HTML file is essentially one line and that alone breaks a lot of tooling.

How to use the HTML Minifier

  1. Paste your HTML

    Type or paste the markup, or drop an .html file onto the editor.

  2. 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.

  3. 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.

  4. 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?

Much. It is essentially one line with no comments, so a stack trace or an error message pointing at line 1 is not useful. Keep an unminified copy and map production errors back to it, which is what a source map is for CSS and JS but has no HTML equivalent.

Will minification break my page?

Only if you enable the aggressive options. Collapsing whitespace between inline elements changes rendering, and removing optional tags is only safe if the HTML5 parser infers them the way you expect. The defaults here are the subset that does not change how the page renders.

Does minifying actually help load time?

A little, and less than the raw byte number suggests, because gzip and Brotli already compress repeated whitespace very efficiently. Expect a few percent on top of compression, more on large templated pages. Compare the compressed sizes before and after rather than the raw ones.

Can I minify JS and CSS inside my HTML?

Yes, via the inline script and style options, which hand those blocks to the same minifiers used by the dedicated JS and CSS tools. It is worth doing when the inline blocks are substantial.

Why did my comments not all disappear?

Conditional comments and comments in the IE conditional format may be preserved, and anything inside a script or style block is treated as code rather than markup. Comments that matter for licensing or documentation should be kept in the source file rather than the output.

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