HTML Minifier

Strips comments and unnecessary whitespace from HTML to reduce its size. Useful for seeing what minification saves, and worth knowing where HTML whitespace is significant before you ship the result.

Live demo · real result from this tool

Minified HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Spring menu — Café Lumen</title></head><body><header><h1>Spring menu</h1><nav><a href="/">Home</a> | <a href="/menu" class="active">Menu</a></nav></header><main><p>Fresh dishes from <strong>local farms</strong>, served <em>all day</em>.</p><ul><li>Asparagus soup &mdash; &euro;7</li> <li>Pea &amp; mint risotto &mdash; &euro;14</li></ul><img src="/img/risotto.jpg" alt="Pea and mint risotto in a white bowl" width="640" height="420"><pre>Open daily  08:00 – 22:00</pre></main></body></html>
Saved8.5%
Original
614 B
Minified
562 B

Processed on your device — nothing is uploaded.

How to use HTML Minifier

  1. Paste your HTML.
  2. Read the minified output and the size saved.
  3. Check inline elements and any pre or textarea content before using it.
  4. Whitespace between inline elements is significant — removing it joins words together.
  5. Content in pre and textarea must be preserved exactly.
  6. Keep minification in your build; do not commit minified HTML as source.

HTML whitespace is not always insignificant

Unlike JSON, HTML has places where whitespace matters. A space between two inline elements is a real space in the rendered output, so removing it runs words together — &lt;b&gt;one&lt;/b&gt; &lt;i&gt;two&lt;/i&gt; becomes “onetwo”. Content inside &lt;pre&gt; and &lt;textarea&gt; is preserved verbatim and must not be touched at all. Elements with white-space: pre in CSS have the same constraint, which a minifier cannot see because it does not read your stylesheet. This is why aggressive HTML minification occasionally produces visible layout bugs where JavaScript minification does not.

The savings are smaller than they look

Removing whitespace from a typical HTML document saves 10–20% of the raw bytes, and most of that is recovered by gzip or Brotli anyway, since repeated indentation compresses extremely well. The real page-weight wins are elsewhere: images, which are usually the bulk of a page; JavaScript, which costs parse and execution time as well as bytes; and web fonts. Minifying HTML is worth doing in a build because it is free, and it is not where a slow page gets fixed.

Do it in the build, never by hand

Minified HTML is unreadable and undiffable, so it should be a build output rather than something you commit. Every static site generator and bundler does it, as do most CDNs at the edge. If you are minifying by hand and pasting the result back into your source, you have made the file permanently harder to maintain to save bytes that compression was already handling.

Frequently asked questions

What does HTML minification remove?
Minification removes unnecessary whitespace, line breaks, comments, and optional closing tags where allowed by HTML5 spec. It creates the smallest valid HTML output.
How much file size reduction can I expect?
Typical reduction is 10-30% depending on code style. HTML with lots of comments and indentation compresses more. The tool shows exact before/after byte counts.
Is minified HTML still valid?
Yes, minified HTML is fully valid and renders identically to formatted HTML. Minification only removes redundant characters that don't affect parsing or display.
How much smaller does minifying HTML make a page?
Typically 10–20% of the raw bytes, and considerably less after gzip or Brotli, which already compress repeated whitespace very efficiently. Images and JavaScript are where page weight actually lives.
Can minifying HTML break my page?
It can. Whitespace between inline elements is rendered, so removing it joins words; content in pre and textarea must be left alone; and elements styled with white-space: pre are invisible to a minifier. Check the rendered result rather than only the markup.
Should I minify HTML if my server uses compression?
It is worth keeping in a build because it costs nothing, but expect a small gain — compression already handles whitespace well. Do not spend effort here while images and scripts are unoptimised.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close