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.