How Much Does Minifying HTML Save? Measured on 5 Real Pages (Raw, Gzip, Brotli)
Five real pages minified three ways and compressed with gzip and Brotli: the byte savings are small after compression, and two of the three settings changed how the page renders.
On this page ⌄
Advice says HTML minification saves 10 to 30 percent. Measured on five real pages, the range is wider and lower: 0.0 to 24 percent raw, and 0.2 to 12 percent once Brotli has compressed the result. Two of the three minifier settings tested also changed what the page shows. All numbers below are from a run on 2026-11-02.
Method
Five pages were downloaded with curl (as a desktop Chrome user agent) and the HTML was kept exactly as served: the English Wikipedia article on HTTP, the Hacker News front page, the Python docs page for csv, the GNU "What is free software" page, and the MDN page for <pre>. Each was processed three ways:
- Xerobit (previous implementation): the regular expressions behind the earlier HTML Minifier (strip comments, collapse all whitespace, trim around listed tags), run in Node. Its results are kept here because they show why a tokenizer is needed.
- Xerobit (current): the tokenizer-based minifier that replaced it, in its two modes (safe and aggressive). Measured at the end of this guide.
- Safe: html-minifier-terser 7.2.0 with
collapseWhitespaceplusconservativeCollapse, andremoveComments. - Aggressive: html-minifier-terser with whitespace collapse (no conservative flag), comments, optional tags, attribute quotes, redundant, empty and boolean attributes, short doctype, and CSS and JS minification.
Sizes are bytes of UTF-8. Gzip is Node zlib at level 9 and Brotli is quality 11, the best case; a server that compresses on the fly at lower levels will save a little less. Rendering was checked in Chrome 156 (JavaScript off, network blocked) by comparing document.body.innerText, page height and the text of every <pre>.
Results
Original sizes:
| Page | Raw | Gzip -9 | Brotli -11 |
|---|---|---|---|
| Wikipedia (HTTP) | 605,220 | 93,766 | 69,211 |
| Hacker News | 34,413 | 5,771 | 4,499 |
| Python docs (csv) | 99,642 | 15,126 | 11,126 |
| GNU free-sw | 50,511 | 15,352 | 11,652 |
| MDN (pre) | 192,345 | 26,511 | 19,418 |
Savings, shown as raw / gzip / Brotli percent:
| Page | Xerobit (old) | Safe | Aggressive |
|---|---|---|---|
| Wikipedia | 1.5 / 1.9 / 2.0 | 1.0 / 1.6 / 1.6 | 6.0 / 3.1 / 1.8 |
| Hacker News | 0.9 / 0.3 / 0.2 | 0.0 / 0.6 / 0.7 | 8.8 / 3.7 / 1.1 |
| Python docs | 4.1 / 5.4 / 5.3 | 2.2 / 4.2 / 4.2 | 8.3 / 6.9 / 5.6 |
| GNU free-sw | 7.6 / 10.6 / 12.2 | 6.4 / 9.7 / 10.6 | 11.8 / 11.5 / 11.6 |
| MDN | 22.2 / 14.3 / 10.3 | 21.1 / 10.1 / 8.6 | 24.2 / 13.9 / 8.8 |
What the numbers say:
- Compression keeps most of the win only where whitespace is heavy. GNU and MDN, with deep indentation, still save roughly 9 to 12 percent after Brotli. Wikipedia and Hacker News, which are already tight, save 0.2 to 2 percent.
- In bytes, Brotli savings were 11 B (Hacker News), 585 B (Python docs), 1,358 B (Wikipedia), 1,420 B (GNU) and 2,005 B (MDN) for the Xerobit variant. That is small next to a single image.
- Aggressive saved the most raw bytes but not the most compressed bytes. On Wikipedia it saved 6.0 percent raw and only 1.8 percent with Brotli, less than the 2.0 of the simple whitespace pass, because the extra work (attribute quotes, optional tags) removes text that compresses well anyway.
- An already-minified page gains nothing. Hacker News ships without indentation, so the safe variant saved 0.0 percent raw.
Option by option, the extra raw bytes saved across all five pages (982,131 bytes total) by html-minifier-terser, each alone on top of a no-option pass: removeAttributeQuotes 29,903 (3.0 percent), collapseWhitespace 26,942 (2.7 percent; the conservative form 22,933), removeComments 9,724 (1.0 percent), removeOptionalTags 5,955 (0.6 percent), and everything else under 1,000 bytes. In Brotli terms, removeAttributeQuotes was negative (-595 bytes: it made the total slightly worse), and only comments and whitespace saved more than 1,500 bytes. A parse and re-serialize pass with no options already saved 19,151 bytes (18,090 of them on the MDN page; the cause was not investigated).
What broke
| Variant | Pages with identical visible text | Pages with identical <pre> text | Notes |
|---|---|---|---|
| Xerobit (old) | 0 of 5 | 0 of 3 that have <pre> | page height changed on 4 of 5 pages |
| Safe | 5 of 5 | 3 of 3 | page height equal on 3 pages, +2 px and +89 px on the others |
| Aggressive | 3 of 5 | 3 of 3 | Wikipedia and GNU text differed |
The old Xerobit minifier was a regex pass, not an HTML parser, and the failures follow from that. A minimal input shows all three:
<p>Hello <b>big</b> world</p>
<script>
// init
var a = 1;
</script>
<pre>
indented
code
</pre>
becomes
<p>Hello<b>big</b>world</p><script>// init var a = 1;</script><pre>indented code</pre>
The space around <b> is gone, the line comment now swallows the rest of the script, and the <pre> indentation is flattened. On the real pages this showed up as GNUOperati where the text was GNU Operating System, the Hacker News menu losing its spacing (new | past | comments became new|past|comments), and the Python docs page rendering 8,971 px tall instead of 10,085 px (most likely its collapsed code blocks, not confirmed). The parsed inline scripts on these five pages still compiled after the pass (checked with vm.Script), so the script-comment case is not visible there, but it is real. The current minifier is a tokenizer, measured in the next section.
The aggressive variant lost a space on two pages. On Wikipedia a protocol-stack navigation box read IP v4v6 in the original and IPv4v6 after (the original has a space between two inline elements). That is the cost of full collapseWhitespace without the conservative flag, and it is why the safe variant is the one to ship. With the safe set, visible text and <pre> content matched on all five pages. Page height matched on three, differed by 2 px on the Python docs page, and by 89 px on the GNU page (cause not traced).
The current Xerobit minifier
The current HTML Minifier is a tokenizer, not a pattern replace. It never rewrites the inside of <pre>, <textarea>, <script> or <style>, it reads attributes properly (so a > inside a quoted value is fine), and it has two modes:
- Safe (default) collapses every run of spaces and newlines to one space, and removes whitespace only where nothing can render: the edges of the document, around
<html>,<head>and<body>, and inside<head>. It should render exactly like the original whatever the CSS says. - Aggressive also removes spaces next to block-level tags such as
<div>,<p>and<li>. That assumes those tags use their defaultdisplay.
Same five pages, same method (raw / gzip / Brotli percent saved):
| Page | Xerobit safe | Xerobit aggressive |
|---|---|---|
| Wikipedia | 0.9 / 1.6 / 1.6 | 1.2 / 1.7 / 1.6 |
| Hacker News | 0.0 / 0.0 / -0.1 | 0.0 / 0.1 / 0.0 |
| Python docs | 2.3 / 4.1 / 4.4 | 2.8 / 4.5 / 4.7 |
| GNU free-sw | 6.4 / 9.6 / 10.8 | 7.1 / 9.8 / 11.3 |
| MDN | 21.6 / 13.7 / 9.6 | 22.1 / 14.0 / 10.0 |
Rendering in Chrome 156 (JavaScript off, network blocked), comparing document.body.innerText, the page size and the position of the first 400 boxes:
| Variant | Pages with identical visible text | Boxes that moved | Page size |
|---|---|---|---|
| Xerobit safe | 5 of 5 | 0 | identical on all 5 |
| Xerobit aggressive | 3 of 5 | 0 | identical on all 5 |
The two aggressive differences are the CSS dependence described above. On Wikipedia the navigation box styles its nested lists as inline, so the space between IP and the list is visible and aggressive mode removed it (IP v4v6 became IPv4v6). On the Python docs page a line ended with a space that Chrome's text output kept in the original and not in the minified copy; no box moved. Hacker News is already compact, so neither mode saves anything and safe mode ends up 4 bytes larger after Brotli.
The tool is also checked against real parsers in its test suite: the minified JavaScript, CSS and HTML parse to the same tree as the original on a few hundred real files. One thing it still does not do is read your stylesheets, so an element with white-space: pre set by a class (not inline) is treated like any other text in safe mode too; keep such content in <pre> or turn minification off for it.
What each setting removes
- Comments:
<!-- ... -->, except conditional comments in a careful minifier. Safe unless a framework reads them. - Whitespace between and inside tags: safe in block layout, risky between inline elements and inside
<pre>,<textarea>and inline scripts, which a real parser knows to skip. - Optional end tags (
</li>,</p>,</td>and others the HTML spec allows you to omit): valid HTML, but it breaks if the document is consumed as XML. - Attribute quotes, empty and default attributes, boolean attribute values: measurable only in raw bytes; Brotli sees almost none of it.
- Inline CSS and JS minification: under 0.2 percent on these pages because most of their CSS and JS is in external files.
What to do
Compress first: serve Brotli or gzip and you have most of the transfer win. Then add the safe minifier setting if your templates are heavily indented, as GNU and MDN were. Skip attribute and optional-tag removal. To see how a page changes, paste a fragment into the HTML Minifier and check it in the HTML Viewer.
Tested
2026-11-02: Node 25.8.0, html-minifier-terser 7.2.0, Chrome 156.0.8078.48 via playwright-core, Node zlib gzip level 9 and Brotli quality 11. Pages were fetched on that day and will have changed since. The median raw saving for the safe setting was 2.2 percent. The current-minifier section was measured on 2026-11-03 with the same five pages and the same compression settings.
Related tools
HTML / CSS / JS Minifier
Minify HTML, CSS, or JavaScript. Strips whitespace, comments, and unnecessary characters. Shows size reduction percentage.
JSON Formatter
Format, validate, and beautify JSON online. 100% client-side, your data never leaves your browser.
HTML Viewer & Formatter
Paste HTML and see it rendered live in a sandboxed preview. Format and beautify messy markup, inline CSS and JS. Desktop, tablet and mobile widths.
JSON Viewer
Explore JSON as a collapsible tree. Paste JSON and navigate nested structures with expand/collapse and JSONPath copy.
Written by Mian Ali Khalid. More guides in Data & Format.