Skip to main content
SerpGem
Technical SEO

HTML Minifier

Paste HTML to strip whitespace, comments, and empty lines. Shows size before/after and percentage savings. Instant, client-side — nothing uploaded.

How to use this tool3 quick steps
  1. Get your HTML

    Either copy the source of a page (View Source / Ctrl+U) or paste a template / fragment.
  2. Paste below

    We strip whitespace between tags, remove HTML comments, collapse double-spaces, and optionally remove optional closing tags.
  3. Use the minified output

    Drop it into your page or build pipeline. Most static-site generators have built-in minification — this tool is most useful for one-off optimization.
InputHTML to minify

Options

OutputMinified HTML

Use this with

See all 8 tools

HTML Minification Guide

HTML minification: the fastest free page speed improvement

HTML minification removes characters that are invisible to browsers but take up bytes in network transfers: whitespace, comments, blank lines. A typical HTML file can be reduced by 10-30% through minification alone. For high-traffic pages, this translates to significant CDN bandwidth savings and faster initial page loads — which affects Core Web Vitals and search rankings.

What minification removes

HTML comments (<!-- -->), extra whitespace between tags, leading/trailing spaces on lines, multiple consecutive blank lines, and unnecessary spaces around attribute equals signs. These characters are required by humans editing code but mean nothing to browsers or search engines.

What minification does NOT remove

Whitespace that affects rendering (inside inline elements, pre/code blocks), significant whitespace in attribute values, inline script content, and inline style content. A safe minifier only removes provably non-semantic whitespace — this tool does not rewrite inline JavaScript or CSS.

Minification and Core Web Vitals

Smaller HTML files reduce Time to First Byte (TTFB) and improve First Contentful Paint (FCP). HTML is render-blocking — the browser cannot display anything until it receives and parses the HTML document. Reducing its size by 20-30% has a measurable effect on low-end devices and slow connections.

HTML comments and SEO

Google can read HTML comments — they're part of the document's source. While they don't affect rankings, they do increase page size and can inadvertently expose development notes or internal documentation. Minification removes them before deployment as both a performance and hygiene measure.

Build pipeline integration

Production-grade minification belongs in your build pipeline (webpack, Vite, Parcel, Hugo pipelines, etc.) not as a manual step. Tools like html-minifier-terser handle edge cases that this tool doesn't (inline JS/CSS minification, optional tag removal). Use this tool for quick testing and verification.

Gzip and Brotli amplify minification gains

Minification reduces raw file size. Gzip/Brotli compression (enabled on most CDNs) compresses the already-minified output further. Whitespace and repeated patterns compress extremely well, so minification before compression compounds the savings — typically 5-15% additional gain on top of compression alone.

Pro Tips

Verify rendering after minification

After minifying, paste the output into a browser DevTools console or an online HTML renderer to verify the page renders identically. While this tool only removes safe whitespace, always verify before deploying to production.

Keep IE conditional comments

This tool preserves <!--[if IE]> conditional comments, which affect real rendering in older IE browsers. Regular HTML comments <!-- --> are removed. If you need to preserve specific comments, check your output carefully.

Minify component templates for savings

Even if your final HTML is minified by your framework, minifying individual HTML template files in your CMS reduces the payload for static page generators. WordPress themes, Shopify templates, and similar CMSes often have bloated template whitespace.

?

Frequently Asked Questions

Will minification break my page?
This tool only removes whitespace that's provably non-semantic: whitespace between block-level HTML tags, empty lines, and HTML comments. It doesn't modify inline scripts, inline styles, or whitespace inside elements where it affects rendering (like inside <pre> or between inline elements like <span>). That said, always test after minifying.
How much size reduction should I expect?
Typical HTML files see 10-25% reduction. Well-formatted, heavily indented code (common with template engines and CMS output) can see 30-40% reduction. Minifying already-compact HTML with minimal whitespace may only save 2-5%. The tool shows exact byte savings so you can decide if it's worth it.
Should I minify or use gzip instead?
Both — they work together. Gzip compression alone gives 60-80% size reduction for HTML. Minification before gzip gives another 5-15%. For most modern sites, gzip (or Brotli) is the high-impact step; minification is complementary. Enable compression on your server first, then minify for marginal additional gains.
Can I use this for CSS and JavaScript?
This tool is HTML-specific. CSS and JavaScript have their own minification semantics (removing semicolons, renaming variables, removing dead code). Use dedicated CSS minifiers (csso, cssnano) and JS minifiers (Terser, esbuild) for those file types. Applying HTML minification logic to CSS/JS would break them.