Home / Developer tools / HTML minifier

HTML Minifier

Make your HTML smaller. The minifier removes what the browser does not need, keeps what it does, and shows the bytes saved, before and after gzip.

What to remove or shorten

Minified HTML

What gets removed

  • Comments. Conditional comments and comments that start with !, which are often licenses, can be kept.
  • Spaces, tabs and line breaks between block elements, and at the start and end of block elements.
  • Runs of spaces inside text, which are reduced to the one space the browser shows.

What gets shortened

  • Boolean attributes: disabled="disabled" and checked="" become disabled and checked.
  • Empty attributes: class="", id="" and style="" are removed. An empty alt is kept, because it has a meaning.
  • Default types: type="text/javascript" on a script and type="text/css" on a style are not needed.
  • Class values: extra spaces between class names are removed.
  • Inline CSS: style tags and style attributes are minified.
  • JSON in script tags, such as structured data, is compacted.
  • Quotes: optional, off by default. Quotes can be removed from values that have no spaces or special characters.

What stays untouched

  • The content of pre and textarea, where every space counts.
  • JavaScript in script tags, which is not rewritten here. Use the JavaScript minifier for scripts.
  • A single space between inline elements, such as between two links in a line of text.
  • Optional closing tags such as </li> and </p> are not removed. That saves little, and it makes the code harder to check.

Size and gzip

The results show the size before and after, and the gzip size of both, which is closer to what visitors download. The saving is smaller after gzip, because gzip already shrinks repeated text, but it is still worth having, and it helps most on pages with a lot of whitespace.

Good to know

  • Whitespace between inline elements is visible. If your layout depends on spaces between inline-block items, check the result.
  • Keep your readable source and publish the minified copy.
  • A page with an unclosed tag is minified as it is read by a browser, so fix warnings first.

To read minified code, use the HTML beautifier. To tidy your own code, use the HTML formatter. The HTML minification guide explains more, and the CSS minifier reduces your stylesheets too.

Frequently asked questions

How do I minify HTML?

Paste your HTML in the box and copy the result. The tool shows how many bytes were saved.

Is minified HTML safe?

Yes, with the options used here. The browser shows the same page. Check pages that rely on spaces between inline elements, and keep a readable copy of your source.

Does it minify JavaScript?

Scripts are not rewritten. Only the spaces around them are trimmed, and JSON in script tags is compacted. Use the JavaScript minifier for scripts.

How much smaller will my HTML be?

Often 10 to 25 percent before gzip, depending on how much whitespace and how many comments there are. The tool shows the exact numbers.