HTML minifier
What HTML minification does
The minifier parses the document and removes what the browser ignores: comments, whitespace between tags, optional quotes and other redundant characters. The page renders the same, with fewer bytes to download. The tool uses the open-source htmldoc minifier, which understands the HTML structure rather than blindly stripping text.
Gains are usually smaller than for CSS or JavaScript, because most HTML is content. They add up on large, template-heavy pages and on pages served many times a second.
Things to keep in mind
- Whitespace inside pre and textarea elements is kept, because it is meaningful there.
- Conditional comments and comments used by tools (for example ad or tag-manager markers) may be removed; check before deploying.
- Server-side compression matters more than minification for HTML. Make sure gzip or Brotli is on.
- Minify generated output, not the templates you edit.
Common questions
How much does HTML minification save?
Often 5 to 20 percent of the raw size, more on pages with heavy indentation or long comments. After gzip the difference is smaller.
Does Google prefer minified HTML?
Google does not rank minified pages higher. It does reward fast pages, and every byte removed from the critical HTML helps a little on slow connections.
Can I minify HTML that contains inline scripts and styles?
Yes. Inline style and script blocks are kept working. For the best result, minify large inline blocks with the CSS and JavaScript minifiers as well.