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?
What about comments?
<!-- ... --> sections. IE conditional comments are preserved (they are functional, not just text).Will quote stripping break anything?
How much smaller?
Inline scripts and styles?
Email template minification?
Related tools
Last updated: 2025-01-15