Skip to content
Toolbench

HTML Minifier

Shrinks HTML without changing what it renders — the space between two inline elements is a word gap, and it is kept.

Runs entirely in your browser

Loading tool...

How to use

  1. Paste the HTML you want to shrink.
  2. Leave the defaults unless you have a reason — they are the safe ones.
  3. Minify, then copy or download the result.
  4. Attribute-quote removal is off by default; turn it on only if you have checked the output.

Features

  • Keeps the whitespace that renders and removes the whitespace that does not.
  • Leaves pre, textarea, script and style contents byte for byte.
  • Keeps conditional and licence comments, which a build step or a browser still acts on.
  • Reads a tag character by character, so a > inside an attribute value is not mistaken for the end of the tag.

Frequently asked questions

Why is my file not much smaller?
Because the safe wins in HTML are small. Most of a page’s weight is in its script, styles and images, none of which this touches — and the whitespace that could be removed without changing the rendering is usually indentation only. Serve the result with gzip or brotli compression, which will save far more than minifying ever does.
Why keep the space between two tags?
Because `<span>a</span> <span>b</span>` renders as "a b" and removing that space renders "ab". It is a word gap, not indentation. Whitespace is only removed outright next to block-level elements, where the browser never rendered it in the first place. That is the difference between a minifier and a text mangler.
Should I remove attribute quotes?
Usually not. It is valid HTML and it saves two bytes per attribute, but the result is harder to read, easy to break with a later edit, and confuses some templating and editor tooling. It is off by default and quotes are only dropped where the value contains nothing that needs them.

Strip comments and whitespace from a stylesheet without touching what is inside a string or a data URI.

Indents XML without editing it: mixed content keeps its spacing, and a tag that does not match is named with the line it is on.

Escape text so a browser renders it instead of running it — and read entities back into the characters they stand for.

Strip what an editor left behind — metadata, comments, fourteen-decimal coordinates — without changing what the file draws.

Indent HTML without changing what the page renders — no line break lands where a space was not already allowed.

HTML Minifier — Compress HTML Without Breaking It