HTML Minifier explained with worked examples
The HTML Minifier does one simple job: it takes HTML with all the space a person needs to read it and returns the same HTML with only the space a browser needs. Four worked examples below show exactly what changes and what does not, with real byte counts taken from the tool itself, so you can check your own results against them.
At a glance
Example 1: the sample card, 91 bytes to 64
The tool opens with a small card: a div, a heading that reads Hello, a comment that says a note, and a paragraph that reads Welcome to WhiteUI. As written it is 91 bytes. The minified version is <div class="card"><h2>Hello</h2><p>Welcome to WhiteUI.</p></div>, which is 64 bytes, so 27 bytes are saved and the page is 30% smaller. The comment is gone, the four line breaks are gone, the six indentation spaces are gone, and the two spaces around Hello are gone. The class name, the words and the tags are untouched.
Example 2: a small page, 291 bytes to 198
Take a complete small page: a doctype, a head with a title, and a body with a heading, a paragraph and a three-item list, with a comment that reads page title in the head. As written it is 291 bytes. The minified version is 198 bytes, so 93 bytes are saved, or 32% smaller. The comment, which is 19 characters on its own, disappears. The heading <h1> Hello world </h1> becomes <h1>Hello world</h1>, with the words still separated by one space, so it reads the same. Every line break and every indent between tags is gone, and the whole page sits on one line.
Example 3: a navigation list, 147 bytes to 125
A navigation list is mostly tags and links, so there is less dead weight to find. A nav with three links, Home, About and Contact, is 147 bytes as written and 125 bytes minified, so 22 bytes are saved, or 15% smaller. The links themselves, including the slash in each href, are copied exactly. Pages that are mostly markup save a smaller percentage than pages with long comments or deep indentation, and that is normal: the saving depends on how much whitespace the original had, not on how big the page is.
Example 4: the preformatted-text trap, 61 bytes to 49
Now the case where minifying changes the meaning. A pre block holding a few lines of code is 61 bytes as written. Minified, it is 49 bytes, so 12 bytes are saved, or 20% smaller, but the result is one line: <pre>function hello() { return "keep me"; }</pre>. The indentation and the line breaks that made the code readable are gone, because this minifier collapses whitespace everywhere, including inside pre blocks. The saving is real and the damage is real too, which is why you check pre blocks before you publish a minified page.
What never changes
Across all four examples, three things never change. Attribute names, values and quotes are copied exactly as written: class="card" stays class="card". The words on the page keep their single spaces, so sentences read exactly as before. And nothing is sent anywhere: the whole job runs in your browser, so the HTML you paste never leaves your computer.
The common mistake
People see a small percentage, such as the 15% on the navigation list, and think the tool did nothing. It did exactly what it was asked to do: the list had only 22 bytes of removable space in it, and all 22 were removed. The percentage is small because the original was already tight, not because the tool missed something. Judge the result by the saved number, not by the percentage alone.
Frequently asked questions
What does the HTML Minifier change in my HTML?
It removes comments and collapses whitespace: line breaks, indentation and doubled spaces go, while tags, attributes and single spaces inside text stay.
How much does the sample page save?
The sample goes from 91 bytes to 64 bytes, saving 27 bytes, or 30% smaller.
Why did my navigation list only save 15%?
Because it had only 22 bytes of removable space in 147 bytes. Pages that are mostly markup save a smaller percentage than pages with long comments or deep indentation.
Does minifying change a pre block?
Yes. A 61-byte pre block becomes 49 bytes on one line, with its indentation and line breaks gone, so check pre blocks before you publish.
More guides on the HTML Minifier
- How to use the HTML Minifier — step by step
- HTML Minifier formula — how it actually works
- HTML Minifier for beginners — start here
- Common mistakes people make with the HTML Minifier
- HTML Minifier vs doing it by hand — which is faster?
- HTML Minifier — The Complete Guide
- How to get an accurate result from the HTML Minifier
- HTML Minifier for students — with examples
- HTML Minifier for homeowners and DIYers
Try the HTML Minifier — free, in your browser.