What is HTML Minification?
HTML minification is the process of removing unnecessary characters from HTML source code without changing how the browser renders the page. This includes stripping whitespace between tags, removing comments, collapsing boolean attributes, removing optional closing tags, and eliminating redundant attribute quotes. A typical HTML document carries a surprising amount of dead weight -- indentation for readability, comments left by developers, default attribute values the browser already assumes, and closing tags that the HTML specification marks as optional. Minification strips all of it, leaving you with the smallest possible markup that still produces the same visual and functional result.
The size savings from HTML minification vary depending on how the original document is written. A heavily commented, well-indented HTML file with verbose attribute syntax might shrink by 15-25%. A more compact file might only drop 5-10%. These percentages sound modest compared to CSS or JavaScript minification, but they apply to a resource that blocks page rendering -- the browser cannot start painting until it has parsed the HTML. Every byte saved in the HTML document directly reduces the time to first render. On slow connections -- mobile networks in emerging markets, congested public WiFi -- those milliseconds add up.
Minification and gzip compression are complementary, not redundant. People sometimes argue that since the server gzips HTML before sending it, minification is pointless because gzip already removes repetition. This is wrong. Gzip works by replacing repeated byte sequences with references. Minification eliminates bytes that gzip would have to encode in the first place. A minified-then-gzipped file is always smaller than a gzipped-only file. Tests on real-world pages consistently show a 2-5% size reduction even after gzip when minification is applied first. At scale -- millions of page views per day -- that difference translates into measurable bandwidth savings and faster load times.