GUIDE深度 · Deep dive

Which HTML Whitespace Matters

HTML collapses repeated whitespace by default, but pre and textarea preserve it, and whitespace in script/style can be syntactic; a single space between inline elements renders as a gap.

更新 2026-10-31 · 公式可核验

Must preserve

pre/textarea: displayed as-is.

script/style: whitespace in strings and selectors.

Whitespace inside these elements is content, not formatting.

Easy to miss

There is a space between <span>a</span> <span>b</span>.

Gaps in inline-block layouts.

Browsers collapse whitespace differently at different widths, so test desktop and mobile.

FAQ

How to minify safely?

Use mature tools and visual regression tests; avoid hand-written regex.

Why garbled Chinese after minifying?

Check that the encoding declaration matches the file encoding.

Sources

Related calculators

HTML MinifierRemove HTML comments, indentation and extra whitespace while preserving pre, textarea, script and style content.

More guides

What HTML Minification DoesRead guide