HTML Minifier
Strip comments, collapse whitespace and drop redundant attributes — safely.
About HTML Minifier
A browser already collapses any run of whitespace inside text down to a single space — but the one space between two adjacent inline tags is real content, and deleting it glues two words together. This minifier respects that boundary: it only drops whitespace beside block-level elements, and it passes the contents of pre, textarea, script and style through byte-for-byte. Everything runs in your browser and the markup is never uploaded.
How to use HTML Minifier
- 1
Paste your HTML into the input box, or press Sample to load a test snippet.
- 2
Toggle remove comments, collapse whitespace and strip redundant attributes to suit the project.
- 3
Enable unquote safe attribute values when you want a shorter output.
- 4
Read the original size, minified size and reduction percentage in the stat cards.
- 5
Copy the result and drop it into your build.
Frequently asked questions
Can this break my page layout?
Whitespace is only removed where the browser would not render it — next to block-level tags such as div, p, li and td. One space always survives between inline tags such as span, a and b, and unknown or custom elements like my-widget are deliberately treated as inline so their spacing is never lost.
Does it minify the JavaScript and CSS inside script and style tags?
No, deliberately. The contents of pre, textarea, script and style are copied byte-for-byte. Minifying JS or CSS needs its own parser, and folding that into an HTML minifier is a classic source of broken builds. The status line reports how many protected blocks were kept.
Why did my file only shrink a few percent?
HTML minification typically saves 5-25% of raw bytes, and most of that comes from indentation. If your server already sends gzip or brotli, those repeated spaces were compressing well anyway — treat minification as a complement to transport compression, not a replacement.
What are the known limitations?
With strip redundant attributes on, type=text is removed from input elements because it is the HTML default — turn that toggle off if your CSS or JS relies on an input[type=text] selector. Input is capped at 2 MB, and anything inside pre is never compacted.