Understanding HTML minification
Whitespace mostly, but watch the inline content.
What HTML minification can safely strip, what it must preserve, and the inline-script and inline-style cases that need separate minifiers.
What's safe to remove.
Whitespace between tags (mostly). HTML comments (<!-- ... -->), unless they're conditional comments for legacy IE (those are 2026-irrelevant but might still appear in old templates). Optional closing tags — </li>, </p> can be omitted before certain following tags by the HTML5 spec. Default attribute values: type="text" on an input is the default; the attribute can be dropped. Boolean attribute values: disabled="" becomes just disabled.
The whitespace gotcha.
Whitespace inside <pre> tags is significant — never strip it. Whitespace between inline elements (span, a, strong) renders as a single space; stripping it produces visible differences. Whitespace around block elements (div, p) is usually safe to remove. A minifier that doesn't distinguish these classes produces output that renders differently from the source — a subtle regression.
Inline scripts and styles.
A page with <script>...</script> blocks needs a JS minifier to handle the script content; same for <style>...</style> and CSS. Good HTML minifiers chain these — html-minifier-terser composes html-minifier + Terser + clean-css. A minifier that skips this leaves the inline content unminified, which defeats half the point.
A worked minify.
Input: <!doctype html>
<html>
<head>
<title>Hi</title>
<meta charset="utf-8" />
</head>
<body>
<p>Hello there.</p>
</body>
</html> Output: <!doctype html><title>Hi</title><meta charset=utf-8><p>Hello there.</p>. The HTML5 parser fills in missing <html>, <head>, <body> tags automatically; the attribute quotes drop when unambiguous; the closing </p> isn't required before end of document.
HTML5 lets you skip a lot
implicit tags + unquoted attributes + optional closes
Result is valid HTML5; parsers fill in the missing structure.
150 bytes → ~85 bytes
= 40 % reduction
Modern frameworks already do this.
Next.js, Astro, SvelteKit, Nuxt all minify HTML in production builds by default. The standalone HTML minifier is for projects that build HTML directly — static site generators that don't auto-minify, hand-built marketing pages, email templates (where every byte counts because the recipient's email client might truncate large messages). Most application authors never run a separate HTML minifier; the framework does it.
The tiny risk profile.
HTML minifiers occasionally break things. The most common: aggressive attribute-value unquoting that fails when the value contains a space or special character; whitespace removal inside <textarea>that changes form behaviour; comment removal that strips conditional comments still in use (rare in 2026). A reasonable build pipeline runs smoke tests after minification — render the minified HTML, compare visual and behavioural output to source. Tools that ship without this safety net surprise users occasionally.