At first glance, whitespace in HTML markup seems irrelevant — the browser will render everything correctly regardless. But a few spots in a document are the exception, where stripping whitespace genuinely changes how the page looks.
What's safe to remove
A minifier strips HTML comments <!-- ... -->, redundant whitespace and line breaks between tags, quotes around attributes with no spaces inside their value, and sometimes optional closing tags like </li>.
The classic bug: merging two words into one
A single space between two inline elements is a visible space on the rendered page, not just formatting in the source. <span>foo</span> <span>bar</span> renders as "foo bar" with a gap; collapse that whitespace naively and it silently becomes "foobar" with no gap at all. A careful minifier only removes whitespace that has no visual effect — between block-level tags, for instance — and leaves whitespace between inline elements alone.
Minification versus readability during development
During development, HTML is usually left formatted with indentation, since that makes it easier to spot structure in DevTools. Minification only gets applied to the final build before publishing, once human readability no longer matters.
Why you'd need this
- Shrink an HTML page's size before publishing it to production.
- Strip developer comments out of the final markup.
- Avoid mistakes by only removing whitespace where it's genuinely safe.
Why word-wrapping scripts change the stakes
Languages written with spaces between words, like English, rely on those spaces both for meaning and for the browser to know where it's allowed to wrap a line. Scripts like Thai or Lao don't use spaces between words at all, and the browser has to guess wrap points using dictionary-based line-breaking rules instead — which means whitespace-collapsing bugs in a minifier are far more likely to slip by unnoticed in space-delimited text like English, where an accidental merge still reads as an odd but plausible-looking word, than in scripts where every space is either meaningful punctuation or entirely absent.