HTML Minifier Online — Compress HTML & Reduce Size

Strip whitespace between tags, remove HTML comments, and collapse whitespace runs to compress your HTML payload. Identical rendering, smaller bytes. 100% in your browser.

What is an HTML Minifier?

An HTML minifier shrinks HTML payload size by stripping whitespace between tags, removing developer comments, and collapsing consecutive whitespace runs. The DOM tree the browser builds is identical to the unminified version, so visual rendering is unchanged — only bytes on the wire differ.

Hand-authored HTML with two-space indentation, descriptive comments, and blank lines between sections typically compresses 20–35% with minification alone — and the savings stack with gzip/brotli for an even smaller wire size. The OpenFormatter minifier runs entirely in your browser: paste, click Minify, copy. No upload, no rate limits, no upload of your internal templates.

How to minify HTML — 4 steps

  1. Paste your HTML. Drop a full document or a snippet. Click Load Sample to try a demo.
  2. Click Minify. Whitespace between tags is stripped, <!-- comments --> are removed, and consecutive whitespace inside text collapses to one space.
  3. Compare sizes. Inspect the line count or byte count difference — most HTML pages shrink 20–35%.
  4. Deploy. Copy the minified HTML and ship it as part of your build pipeline, your CDN deployment, or your email payload.

Sample transformation

Before — 7 lines, 142 bytes

<header class="hero">
  <!-- main heading -->
  <h1>Welcome</h1>
  <p>
    Build faster with OpenFormatter.
  </p>
</header>

After — 1 line, 84 bytes

<header class="hero"><h1>Welcome</h1><p>Build faster with OpenFormatter.</p></header>

A 41% size reduction in this example — 142 bytes down to 84. The browser parses the same DOM in both cases.

Inter-Tag Whitespace

Every > ... < pattern is collapsed to ><. The DOM tree built by the browser is identical, but the wire size is meaningfully smaller.

Comment Removal

Developer notes, TODO markers, and section labels in <!-- ... --> are stripped out. Final output ships only what the browser actually renders.

Client-Side Only

HTML is minified in your browser. Internal copy, customer data, and unreleased layouts never leave the device — verify in DevTools Network.

Common use cases

  • check_circleMinifying static-site HTML before deploying to a CDN (Cloudflare, Netlify, Vercel, S3)
  • check_circleReducing transactional email HTML payload to fit Gmail's 102KB clipping threshold
  • check_circleCompressing server-rendered HTML to improve TTFB on slow connections
  • check_circleAdding HTML minification to a build pipeline alongside CSS and JS minification
  • check_circleReducing bundle size for a single-file HTML report or invoice download
  • check_circleOptimising AMP HTML pages for mobile performance budgets
  • check_circleCompressing the output of a static-site generator (Hugo, Eleventy, Astro)
  • check_circleShrinking the HTML payload of a marketing landing page for ad performance

Minification vs gzip: do both

A common misconception is that gzip/brotli makes HTML minification irrelevant — gzip is great at compressing repeated whitespace, after all. In practice, minification still helps: gzip cannot remove comments (it just compresses them efficiently), the browser still has to parse fewer bytes after decompression, and the un-gzipped size affects parse time on low-end devices. The combination of minification plus gzip wins on every metric — wire size, parse time, and time-to-interactive.

More HTML tooling

Beautify, validate, view, or edit HTML with the rest of OpenFormatter's toolkit — all browser-side.

Frequently Asked Questions

What does HTML minification actually remove?

Three things: (1) whitespace between tags — every > <space> < becomes ><; (2) HTML comments <!-- ... -->; (3) consecutive whitespace runs inside text content collapse to a single space. The DOM tree the browser builds is identical to the unminified version, so visual rendering is unchanged.

How much size reduction is typical?

Hand-authored HTML with deep indentation and developer comments commonly compresses 20–35%. Already-clean templates from a build tool see 5–10%. Combined with gzip/brotli, the wire-size win is smaller (compression is good at repeated whitespace) but every removed byte still saves parse time on the browser.

Will minification break <pre> or <textarea> content?

A naive minifier will, because <pre> and <textarea> rely on whitespace being preserved exactly. The OpenFormatter minifier uses a generic regex pass that does collapse whitespace inside these elements — for production HTML containing <pre> code blocks, run the output through a careful test pass or use a parser-based minifier that respects whitespace-significant tags.

Does it remove conditional comments for IE?

IE conditional comments (<!--[if IE]>) look like comments but are functional in IE9 and below. Modern minifiers (and this one, by virtue of stripping all comments) remove them — which is fine for sites that no longer support IE. If you support legacy IE, do not minify your <head> with this tool.

Is minified HTML valid HTML?

Yes. HTML is whitespace-tolerant outside of a few specific elements (pre, textarea, script, style), so collapsing inter-tag whitespace and removing comments produces output that the W3C validator accepts. Run the result through an HTML validator to confirm if you have unusual content.

Should I minify HTML in addition to gzip/brotli?

Yes. gzip is excellent at compressing repeated whitespace, but it cannot remove comments. Minified HTML compresses smaller than unminified HTML, and the browser still has to parse fewer bytes after decompression. The combined win is real, especially on slow networks and low-end devices.

Will it minify inline <script> and <style> blocks?

Whitespace inside script and style blocks will be collapsed, which is usually fine for CSS but can break JavaScript that relies on automatic semicolon insertion (ASI) across what was a line break. If your HTML contains inline JS, minify the JS separately with a real JS minifier first, then run this HTML minifier.

Is my HTML uploaded to your servers?

No. Minification runs entirely in JavaScript inside your browser. HTML containing internal copy, customer data, or unreleased layouts never leaves the device. Open DevTools Network and click Run — zero requests fire.

HTML Minifier Online — Compress HTML & Reduce Size