HTML Minifier

Collapse whitespace and strip comments from markup — while leaving pre, textarea, script and style content exactly as written.

The one thing an HTML minifier must get right

Whitespace in HTML is not decoration — between two inline elements it is a real, rendered space. Delete it and <a>one</a> <a>two</a> becomes onetwo. That is why "remove whitespace between tags" is off by default here: collapsing runs of whitespace down to a single space is safe for every document, while removing it entirely is only safe when you know your layout does not rely on those spaces. Turn it on, then look at the page.

Protected regions

Everything inside <pre> and <textarea> is preserved byte for byte, because whitespace there is visible content. <script> and <style> blocks are also left untouched — minifying them needs a JavaScript or CSS tokenizer, and doing it badly breaks a page instantly. Run those through the JavaScript Minifier and CSS Minifier separately, where the tokenizer is built for the job.

Comments, including the ones you should keep

Standard comments are removed. Conditional comments (<!--[if ...]>) are kept when the option is ticked, since some legacy email clients and old Internet Explorer targets still depend on them. Comments are also how many templating and build systems mark regions, so check the output if your HTML comes out of a generator.

Is it worth it for HTML?

Less than you would hope. HTML compresses extremely well with gzip and Brotli, so a page that saves 20% from minification may save only 2–4% once compression is applied. The real page-weight wins are images, fonts and third-party scripts — minified HTML is a finishing touch, not a fix. It matters most for HTML email, where compression is not applied and some clients enforce a size limit before clipping the message.

Benefits

  • Collapses whitespace and strips comments while protecting pre, textarea, script and style content.
  • Keeps conditional comments, which some email clients still rely on.
  • Whitespace between tags is only removed when you explicitly ask, because that change can join words together.
  • Shows the byte saving and downloads the result as a file.

Limitations to know

  • It does not minify the CSS or JavaScript inside your page — those need their own tokenizers.
  • It does not remove optional quotes or closing tags, which are valid but make markup fragile.
  • Gzip already compresses HTML well, so the live saving is usually only a few per cent.

Common mistakes to avoid

  • Turning on "remove whitespace between tags" without checking the page, then finding inline links run together.
  • Minifying a template file and breaking the comment markers a build system depends on.
  • Treating HTML minification as a performance fix when images and third-party scripts are the real weight.

Alternatives

Minify the assets separately with the CSS Minifier and the JavaScript Minifier. For XML documents use the XML Formatter.

Last updated: August 2026 · Reviewed by the AI Toolbox editorial team.

Frequently asked questions

Why is "remove whitespace between tags" off by default?

Because whitespace between inline elements renders as a real space. Removing it can visually join words. Turn it on only after checking the page.

Does it minify my inline CSS and JavaScript?

No. Those need dedicated tokenizers — use our CSS Minifier and JavaScript Minifier on those blocks, then paste them back.

Will it strip my quotes or optional closing tags?

No. Those transformations are valid HTML but make the output fragile to edit and can trip up naive parsers, so this tool leaves them alone.

Does minifying HTML help SEO?

Only indirectly, through slightly faster loading. Google does not reward minified markup by itself, and gzip already does most of the work.

Related tools