Skip to content

HTML Minifier

Shrink HTML by removing comments and whitespace — without changing how the page looks.

Original
777 B
Minified
506 B
Saved
271 B (34.9%)

Original HTML

Tab inserts indentation. Press Escape, then Tab, to move focus out of the editor.

Minified HTML

How to minify HTML

  1. Paste your HTML on the left, or open or drop an .html file.
  2. The minified HTML appears on the right, with the original size, new size and bytes saved above it.
  3. Switch individual optimisations on or off if you need to keep something.
  4. Copy the result or Download it as minified.html.

Compress HTML without breaking the page

Minifying HTML removes characters that browsers ignore, so pages download faster and use less bandwidth. The hard part is doing it safely: whitespace is meaningful in some places. <b>Hello</b> <i>world</i> needs its space, and code in a <pre> block must keep its indentation.

This HTML minifier is deliberately conservative. It removes comments (keeping conditional comments), collapses runs of whitespace, drops whitespace only next to block-level elements where browsers don't render it, and never touches <pre>, <textarea> or inline JavaScript. The page looks exactly the same — just smaller.

What gets minified

  • HTML comments and redundant whitespace between block elements.
  • Inline CSS in <style> blocks and style attributes.
  • JSON and JSON-LD structured data, with every value preserved exactly.
  • Boolean attributes (checked="checked" → checked) and default types such as type="text/javascript".

When minifying HTML helps

  • Static sites and landing pages deployed without a build step.
  • HTML emails — Gmail clips messages whose HTML is larger than about 102 KB.
  • Embedding HTML snippets in JSON, JavaScript strings or database fields.

Related HTML tools

Keep a readable copy for editing: the HTML formatter turns minified code back into indented HTML. Before you minify, it's worth running the HTML validator — broken markup is much harder to spot once everything is on one line. You can also compare the result in the HTML viewer or keep working on it in the online HTML editor.

Frequently asked questions

Is minified HTML safe to use?
Yes. This minifier only removes what browsers ignore: comments, redundant whitespace next to block elements and default attributes. Whitespace inside <pre>, <textarea> and scripts is kept, and single spaces between inline elements are preserved, so the page renders the same.
How much smaller will my HTML get?
It depends on how much indentation and how many comments the file has. Typical hand-written pages shrink by 10–30%. The tool shows the original size, the minified size and the exact bytes saved.
Does it minify JavaScript?
Inline JavaScript is left unchanged, because shrinking it safely needs a full JavaScript parser. Inline CSS and JSON-LD structured data are minified.
Do I still need gzip or Brotli?
Yes. Server compression and minification work together: minification removes characters, compression encodes the rest. Most hosting platforms enable compression automatically.
Can I reverse minification?
Removed comments cannot be restored, but you can make minified code readable again with the HTML formatter.