Skip to main content

Html Minifier

HTML minification removes whitespace, comments, and redundant attributes from HTML code to reduce file size and improve page load speed. Our minifier applies safe transformations (whitespace collapse, comment removal) and optional aggressive optimizations (attribute quote removal, boolean attribute shortening) with a before/after size comparison.

Input HTML

Minified (% smaller)

Share this tool
Developer Tools

About the HTML Minifier

HTML minification removes whitespace, comments, and redundant attributes from HTML code to reduce file size and improve page load speed. Our minifier applies safe transformations (whitespace collapse, comment removal) and optional aggressive optimizations (attribute quote removal, boolean attribute shortening) with a before/after size comparison.

How to use it

  1. Paste your HTML into the input area.
  2. Select minification options: remove comments, collapse whitespace, minify inline CSS/JS.
  3. See minified output with size reduction percentage.
  4. Copy output or download as .html file.

Formula & methodology

Safe transformations: collapse multiple whitespace to single space; remove HTML comments (<!-- -->); remove optional closing tags (</li>, </td>). Aggressive: remove quotes from safe attributes; boolean attributes (disabled="disabled" → disabled); remove default type on scripts (type="text/javascript"). Typical savings: 5–30% depending on original formatting.

Common use cases

  • Production deployment: reducing HTML payload for faster page loads
  • CDN optimization: smaller files mean lower storage and transfer costs
  • Email templates: some clients are sensitive to whitespace in HTML emails
  • Build pipelines: Webpack/Vite plugins that minify HTML in CI/CD
  • Template compression: squeezing blade/twig templates before serving

Frequently asked questions

Typically 10–30% size reduction on unoptimized HTML; less on already-compact templates. The real-world impact on load time is modest compared to larger wins: image optimization (often 50–80% size reduction), CSS/JS minification (20–60%), and HTTP/2 server push. HTML minification is a low-effort, no-risk optimization worth doing in any production build pipeline, but don't expect it to dramatically move Core Web Vitals scores alone.
Yes for standard HTML comments (<!-- -->). Exceptions: IE conditional comments (<!--[if IE]>) are still parsed by old IE but are otherwise invisible — safe to remove for modern-only sites. Server-side include (SSI) directives that look like comments must be preserved. License blocks embedded in comments should be removed from HTML but preserved in source files. Never remove HTML comments generated server-side that contain live data or config.

Related tools

All Tools →

Embed this tool on your site

Free for personal and commercial use. Just copy the snippet below.