Skip to content
TypeParser
All tools

HTML Minifier

Strip whitespace and comments from HTML.

beats willpeavy.com edge: Comment + quote stripping toggles
input.html
paste HTML
Guide

About HTML Minifier

Collapse whitespace between tags, optionally remove HTML comments, optionally remove quotes around safe attribute values. Reports byte savings. Useful for inline HTML in scripts, email templates, and one-off optimizations. For full-page minification, integrate in your build (terser-html, html-minifier-terser).

When to minify HTML

For most production sites, your build tool already minifies. Reach for this when:

  • Inlining HTML in a JavaScript string
  • Reducing email template size to fit a 100KB Gmail clip threshold
  • Hand-optimizing a page-load-critical embed
  • Quickly estimating the savings potential

What gets stripped

  • Whitespace between tags (always)
  • Whitespace inside text (toggle, default off)
  • HTML comments (toggle)
  • Optional quotes around safe attribute values (toggle, HTML5)
  • Trailing slash on void elements (toggle)
  • Default attribute values like type="text" on input (toggle)

Common workflows

Inline HTML in a JS template literal. Minify before embedding to save bytes in the bundle.

Optimize an email template. Strip whitespace and comments. Double-check rendering in major clients before sending.

Audit gzipped size. Minify → gzip → see ratio. Most well-written HTML gzips to 20% of source; minify shaves ~10% more before gzip.

Frequently asked questions

Is whitespace inside text content preserved?
Yes — by default, only whitespace between tags collapses. Toggle aggressive to also collapse runs inside text (breaks pre, code, textarea automatically).
What about comments?
Toggle Strip comments to remove <!-- ... --> sections. IE conditional comments are preserved (they are functional, not just text).
Will quote stripping break anything?
Safe attribute values (alphanumeric, no spaces / quotes / special chars) can drop their quotes per HTML5 spec. Toggle Remove safe quotes if your renderer accepts it.
How much smaller?
Typical 15-30% reduction on hand-written HTML; less on template-output HTML that already has tight formatting.
Inline scripts and styles?
Pass through unchanged. Use the dedicated JS Minifier / CSS Minifier on the contents first.
Email template minification?
Email clients are picky — some break on missing quotes or collapsed whitespace. Test before deploying.
How do I minify HTML on the command line or in Node?
The standard library is html-minifier-tersernpx html-minifier-terser --collapse-whitespace --remove-comments in.html, or import it in Node: minify(html, { collapseWhitespace: true, minifyCSS: true, minifyJS: true }). Build plugins (Vite, webpack, Astro) wrap it for you. This page is the no-install way to minify a single file or estimate savings.
How do I minify HTML in WordPress?
Use a caching/optimization plugin that includes HTML minification (WP Rocket, Autoptimize, LiteSpeed Cache) rather than pasting output by hand, since WordPress regenerates pages dynamically. Use this tool for static snippets, custom HTML blocks, or email templates you edit manually.

Related tools

Last updated: 2026-07-04