HTML Minifier

Compress HTML by collapsing the whitespace between elements and removing comments. The minifier is deliberately careful: it keeps a single space where one separates words across inline tags, and it leaves pre and textarea contents untouched.

Your files never leave this device

Minify your HTML Live · Layout-safe

Comments

Turn this on if your build relies on conditional or marker comments.

How to minify HTML

  1. Paste your HTML document or fragment into the box above.
  2. Leave comments stripped unless your build depends on marker comments.
  3. Check the reported saving in bytes and as a percentage.
  4. Test the minified page renders identically before shipping it.
  5. Copy the result, or download it as a .min.html file.

What this minifier does

  • Collapses runs of whitespace between elements to nothing where it is safe.
  • Keeps a single space between text runs, so words never join across inline tags.
  • Preserves pre and textarea contents exactly, spaces and line breaks included.
  • Collapses whitespace inside script and style without altering their code.
  • Removes comments by default, with an option to keep them.
  • Tidies attribute whitespace inside tags without touching attribute values.

Where the bytes are in an HTML document

A formatted HTML page carries a lot of indentation. Deeply nested markup. A component inside a card inside a grid inside a section, can be indented ten or twelve levels, which is twenty-four spaces on every line. Across a few hundred lines that adds up to a meaningful share of the document.

Comments add more. Build-time annotations, commented-out blocks left behind during development, and generator banners all ship to every visitor and are ignored by every browser.

The one thing a careless minifier gets wrong

It is tempting to remove all whitespace between tags. That breaks pages, because whitespace between inline elements is meaningful. <a>Terms</a> <a>Privacy</a> with the space removed renders as "TermsPrivacy".

This minifier keeps a single space wherever text runs meet, and removes whitespace only between tags where nothing textual is separated. That is less aggressive than some tools and it does not silently change how a page reads, which is the trade worth making.

What is protected

  • pre and textarea: contents preserved byte for byte, since whitespace is displayed.
  • script and style: whitespace collapsed but code never rewritten.
  • Attribute values: never touched, so a class list or a data attribute keeps its exact spacing.
  • Conditional comments: kept if you enable the comments option.

How much this actually matters

Be realistic. On a page served with gzip or brotli, which is essentially all of them. HTML minification saves far less than the raw percentage suggests, because indentation is exactly the kind of repetitive content compression algorithms eliminate almost entirely.

The saving is real but modest, typically a few per cent of transferred bytes. It is worth doing as part of a build, and it is not where a slow page gets fixed. Images are almost always the dominant cost, the image compressor and image resizer will do more for load time than any amount of markup compression.

Never edit the minified version

Treat minification as a build step, exactly as you would for CSS and JavaScript. The formatted document is the source; the minified one is output. If you have lost the source, the HTML formatter will reconstruct a readable version, though comments removed during minification are gone for good.

Everything runs in your browser, so unreleased pages and internal templates are never uploaded anywhere.

Attribute values and why they are left alone

It is tempting to normalise whitespace inside attributes as well, since a class list with double spaces looks untidy. This minifier does not, and the reason is that attribute values are data rather than markup.

A data- attribute may carry a JSON payload where spacing inside a string matters. An alt attribute is a sentence read aloud by screen readers, where collapsing spaces changes how it sounds. A title may contain deliberately formatted text. Since there is no reliable way to tell which attributes are safe to touch, none are touched, and the few bytes involved are not worth the class of bug that guessing would introduce.

Frequently asked questions

Can minifying HTML break my layout?

It can if done carelessly, because whitespace between inline elements renders as a space. This minifier keeps a single space wherever text runs meet, specifically to avoid that.

How much smaller will my page get?

Usually 10 to 25 per cent of raw size, but far less of transferred bytes once gzip is applied, since indentation compresses extremely well.

What happens to my pre and textarea content?

It is preserved exactly, including spaces and line breaks, because in both elements whitespace is displayed to the user.

Should I keep comments?

Only if your build or a legacy browser target depends on them. Otherwise they ship to every visitor and are ignored by every browser.

Is minifying HTML worth it?

As a build step, yes. As a performance fix, images are almost always the bigger problem, compressing them will do far more for load time.