1. Home
  2. Tools
  3. HTML minifier

Free · no sign-up · runs in your browser

HTML Minifier

Shrink HTML by removing comments, line breaks and extra spaces, and compress the CSS inside it — with a live count of how many bytes you saved.

HTML input
Minified HTML

In shortPaste HTML and the minifier removes comments, collapses whitespace and compresses inline CSS, usually saving 10–30% before gzip. Code in <pre> and <textarea> is left untouched so the page looks the same.

How to use the HTML minifier

  1. Paste HTML. Paste the page or open an .html file.
  2. Choose options. Comments, inline CSS and inline JS are handled by default; aggressive mode removes even more whitespace.
  3. Check the savings. The size before and after and the percentage saved update live.
  4. Copy or download. Copy the minified code or download minified.html.

What does minifying HTML do?

Minification removes characters browsers don't need: comments, indentation, line breaks and repeated spaces. The page renders the same but the file is smaller, so it downloads and parses a little faster. On a typical hand-written page expect 10–30% savings before gzip or Brotli compression.

Options explained

  • Remove comments — deletes <!-- … --> but keeps old IE conditional comments.
  • Minify inline CSS — removes CSS comments and whitespace inside <style>.
  • Squeeze inline JS — conservatively removes JavaScript comments and blank lines. It never rewrites code, so it can't break scripts. For full JS minification use a bundler such as esbuild or Terser.
  • Aggressive whitespace — removes spaces between block-level tags entirely. Safe for most layouts; turn it off if inline elements lose their spacing.
  • Remove safe attribute quotes — turns class="nav" into class=nav where HTML allows it.

Is minifying HTML worth it?

For a static site or landing page served without a build step, yes — it's free bytes. If your server already uses gzip or Brotli the gain is smaller (compression already squeezes whitespace), but minified HTML still compresses better. Keep the readable original for editing; reformat a minified file at any time with the HTML formatter.

Private by design: this tool runs entirely in your browser. Nothing you paste or open is uploaded to a server.

Frequently asked questions

Does minifying HTML change how my page looks?

No in normal pages. <pre> and <textarea> content is preserved. Aggressive mode can remove a space between inline-block elements; switch it off if you notice that.

How much smaller will my HTML get?

Typically 10–30% for hand-written HTML, more for heavily commented or indented templates. The tool shows the exact saving.

Can I un-minify HTML?

Yes — paste it into the HTML formatter to restore indentation. Removed comments can't be recovered.

Does it minify JavaScript?

It removes comments and blank lines from inline scripts but doesn't rename variables. That keeps it safe; use a dedicated JS minifier for maximum savings.

Is my code uploaded?

No. Minification runs in your browser.

Related tools & guides

Updated 2026-10-22 · by the htmlonline.dev team