The transformation here is deliberately rendering-neutral: runs of whitespace in ordinary markup are collapsed to a single space, which is exactly what a browser already does when it lays the page out, so the result renders identically to what you started with. Removing that whitespace entirely would not be neutral, because the space between two inline elements is rendered and joining them changes the text.
Regions whose whitespace carries meaning are copied through untouched: pre and textarea render their whitespace, while script and style hold code in another language where a collapsed newline can change what runs. Comments are removed except conditional comments, which carry meaning for older versions of Internet Explorer.
Why the saving is modest
-
Whitespace is collapsed, not removed:
one space is left where a run of spaces and newlines was. That single space is often rendered, and deleting it joins words that should be apart.
-
Four kinds of region are preserved whole:
pre, textarea, script and style. Their contents come through exactly as written.
-
Attributes and tags are untouched:
quotes are not removed, optional closing tags are not dropped and boolean attributes are not shortened. Those savings exist but each one relies on parsing rules that vary.
-
Compression matters more than minification here:
gzip and brotli handle repeated markup extremely well, so the difference minification makes to a compressed page is smaller than it looks uncompressed.
Rendering-neutral, not whitespace-free
Runs of whitespace in ordinary markup are collapsed to a single space by the [msm_tool slug="html-minifier"], which is exactly what a browser already does when it lays a page out — so the result renders identically to the original. Removing that whitespace entirely, rather than collapsing it, would not be neutral: the single space between two inline elements is itself rendered, and deleting it joins words that were meant to stay apart.
Four regions are copied through exactly as written
`pre` and `textarea` render their whitespace directly, so collapsing anything inside them would be a visible change rather than an invisible optimisation. `script` and `style` hold an entirely different language, where a collapsed newline can change what actually runs rather than merely how it looks. All four are left untouched rather than run through the same whitespace pass as ordinary markup.
Conditional comments are kept, ordinary ones are not
Every regular HTML comment is removed, with one specific exception: conditional comments, which carry real meaning for older versions of Internet Explorer and would change behaviour if stripped rather than merely changing file size.
What stays untouched, and why each one is a real trade-off
Quotes around attribute values are not removed, optional closing tags are not dropped, and boolean attributes are not shortened to their minimal form. Each of those savings genuinely exists, and each one depends on parsing rules that vary enough between contexts that applying them safely everywhere is a harder problem than the size saved is worth here.
Why the gain matters less than it once did
Gzip and brotli compress repeated markup extremely well, so the difference minification makes to a page that is actually served compressed is considerably smaller than the raw, uncompressed byte counts suggest. Minifying HTML is still worth doing for a file that will not be compressed at all; for one that will, the win is real but modest.