How to use the HTML minifier
- Paste your HTML or drop
.htmlor.htmfiles. - Choose a preset: Safe for templates you’re unsure about, Balanced for most pages, Max for the smallest output.
- Keep license comments on if your markup contains notices you must keep.
- Press Minify and copy or download the result.
- Check the diff and the gzip and brotli sizes to see what changed.
How it works
The HTML is parsed into elements, attributes and text, then written back out with these changes:
| Change | Safe | Balanced | Max |
|---|---|---|---|
| Collapse whitespace | to one space | yes | yes |
Remove comments (except <!--! … --> when kept) |
yes | yes | yes |
Remove redundant attributes (e.g. type="text/javascript") |
type attributes only | yes | yes |
Collapse boolean attributes (disabled="disabled" → disabled) |
no | yes | yes |
| Minify inline CSS and JS | no | yes | yes |
| Sort attributes and class names | no | no | yes |
Text inside pre and textarea is never changed.
Worked examples
- An indented page with comments: comments disappear, indentation collapses and
<script type="text/javascript">becomes<script>. - A code sample in
<pre>keeps every space and line break. - Minifying again gives the same or a smaller result, so it’s safe to re-run.
Tips and common mistakes
- Template syntax: if your HTML contains server-side or framework template tags, use Safe and check the result, as unusual syntax may not parse cleanly.
- Inline whitespace matters: words separated only by a line break in the source still need a space. Safe keeps one, and Balanced keeps spaces between inline elements where they affect layout.
- Use compression too: gzip or brotli on your server saves far more than minification alone.
- Automate for production: minify in your build so every deploy is optimized.
Why use this minifier
Everything happens in your browser, presets explain exactly what changes, pre and textarea content is protected, and you get diff, batch, ZIP and real compression numbers in one accessible tool.
What it won’t change
The minifier never rewrites the text your visitors read, the order of elements or the content of pre and textarea, and it doesn’t touch external files referenced by your page.