Skip to content

HTML minifier

Shrink HTML with a real parser, not a find-and-replace.

Runs in your browser — nothing is sent anywhere.

What HTML minification removes

Comments, and the whitespace between elements that the browser was going to collapse anyway. The saving is smaller than for CSS or JavaScript — usually 5–15% — because HTML is mostly content, and content cannot be shortened.

Whitespace in HTML is not always insignificant

This is the trap. Inside <pre> and <textarea>, every space and newline is displayed exactly as written, so collapsing them changes the page. Between inline elements, a single space is meaningful too — removing the newline between two <span>s can run two words together.

This tool parses the document with the browser's own HTML parser and walks the resulting tree, so it knows which text belongs to a preserved element. The old regular-expression version did not: it collapsed newlines inside <script>, which put an entire script body behind a single // comment and stopped the page working.

What it leaves alone

The contents of <pre>, <textarea>, <script>, <style> and <code>. Attributes are untouched, and no tags are removed even where the standard permits it — closing tags that could technically be dropped are kept, because the few bytes are not worth the confusion later.

Whether it is worth doing

Less than you might think, for a page served with gzip or brotli. The comments are worth removing if they contain anything you would rather not publish; the whitespace saving largely disappears under compression.

Where the bytes actually are

Before spending effort here, look at what the page is really carrying. On most sites the HTML is a small fraction of the payload and the images are the rest — a single unoptimised hero photograph routinely outweighs every byte of markup on the page. Compressing that image will do more for load time than minifying the HTML ever will.

It runs in your browser

Nothing is uploaded.

01

Common questions

Will it break my code?

No. These are real parsers working on a syntax tree. The regex-based tool this replaces did break code, routinely.

Why did it reject my file?

A parser reports syntax errors rather than guessing. The message usually points straight at the problem.

How much smaller will it get?

Roughly 20–35% for CSS, 30–60% for JavaScript, 5–15% for HTML — before gzip.

Is minifying still worth it?

Somewhat. Compression recovers much of the same saving, though the two do compound.

Can it un-minify?

No. Variable names are gone for good — that is where most of the saving comes from.

Is my code uploaded?

No, it is processed in your browser.