← All blog posts

HTML Minifier — The Complete Guide

WhiteUI · A plain-English guide to the HTML Minifier

A web page is mostly words and tags, but the file behind it carries a lot of space a browser never needs: line breaks, indentation, comments, and doubled spaces. The HTML Minifier takes that space out and leaves the page itself alone. This guide covers every part of it: the five rules, the buttons, the numbers, and the cases where you should not minify, so you never have to guess what a setting does.

At a glance

Small page: 32% smaller93 bytes removed198 bytes kept291 bytes in, 198 bytes out
A typical small page goes from 291 bytes to 198 bytes. The 93 bytes removed are the comment, the indentation, and the extra spaces.

The five rules

Minifying follows five rules, in a fixed order. First, comments are removed: anything between <!-- and --> goes, including the markers. Second, every run of whitespace, spaces, tabs and line breaks, collapses to a single space. Third, the space between a closing bracket and the next opening bracket is removed, so > < becomes ><. Fourth, the space after a > and the space before a < are removed, so > Hello < becomes >Hello<. Fifth, the ends are trimmed.

The numbers, all in one place

The sample card the tool opens with is 91 bytes and minifies to 64 bytes, saving 27 bytes, or 30% smaller. A typical small page with a heading, a paragraph and a list is 291 bytes and minifies to 198 bytes, saving 93 bytes, or 32% smaller. A navigation list with three links is 147 bytes and minifies to 125 bytes, saving 22 bytes, or 15% smaller. A shop page with twenty products is 1,744 bytes and minifies to 1,415 bytes, saving 329 bytes, or 19% smaller.

Copy, download, and the three lines

After you paste your HTML in, the result panel shows a big percentage, then three lines. The first line gives the two sizes, Original and Minified, the second gives the bytes saved, and the third says what was done: comments removed, whitespace between tags collapsed. The percentage is (original − minified) ÷ original × 100, so for the sample that is 27 ÷ 91 × 100, which is 29.7%, shown rounded as 30%. When the numbers look right, press Copy minified HTML to put the result on your clipboard, or Download .html to save it as a file called minified.html. Nothing is uploaded at any point: the whole job runs in your browser.

What never changes

Two things are always safe. The words on the page keep their single spaces, so a sentence reads exactly as before: <p>Hello world, this is a test.</p> becomes <p>Hello world, this is a test.</p>, from 49 bytes to 35. Attribute names, values and quotes are copied exactly, so class="card" stays class="card" and a link to /about/ still points to /about/.

When not to minify

Do not minify a page that has a pre block or a textarea whose spacing matters, because the tool collapses whitespace everywhere: a 61-byte pre block comes out as one line of 49 bytes, with its indentation gone, and a 43-byte textarea comes out at 35 bytes. Do not minify a page with a script string that contains the characters <!--, because the tool will eat the string: var s = "<!-- hi -->"; becomes var s = "";. And do not minify a page that is already minified, because the second pass saves nothing: the 64-byte sample output pasted back in comes out at 64 bytes, with 0 saved. Keep your original file for editing, and minify a copy whenever you publish.

The common mistake

People judge the tool by the percentage and miss the saved number. A navigation list that saves 15% still had all 22 of its removable bytes taken out, and a shop page that saves 19% still had 329 bytes taken out. The percentage is small when the original was already tight, and the saved number is what your visitors actually feel, because every byte saved is a byte that does not have to travel to their phone. Read the saved line first, and let the percentage come second.

Frequently asked questions

What are the five minify rules?

Remove comments, collapse each whitespace run to one space, remove the space between tags, remove the space after and before tags, and trim the ends.

How much does a typical small page save?

A 291-byte page minifies to 198 bytes, saving 93 bytes, or 32% smaller.

Does the HTML Minifier change my words or links?

No. Words keep their single spaces, attributes are copied exactly, and &nbsp; codes are left alone; only comments and whitespace are removed.

When should I not minify a page?

When it has a pre block or a textarea whose spacing matters, or a script string containing <!--, because the tool collapses whitespace everywhere and removes anything between comment markers.

Is my HTML sent anywhere?

No. Everything runs in your browser. Nothing is uploaded, stored or logged.

More guides on the HTML Minifier

Try it yourself

Try the HTML Minifier — free, in your browser.

Open the HTML Minifier