Compress an HTML fragment while preserving its text
Admin ·
Spaces between attributes are markup syntax. Spaces between words belong to text nodes and their display depends on CSS. The two compression controls handle these cases separately.
Compress tag syntax first
Paste <p class = "note" >A B</p>. Default compression produces <p class=note>A B</p>. The attribute quotes can be omitted for this value, and the three spaces inside the paragraph remain.
Compare the optional text changes
Add <pre>A B</pre> and <!-- draft --> to the source. Enable both optional controls and compress again. The paragraph reads A B, the preformatted block keeps its spaces and the ordinary draft comment disappears. Check components that style ordinary paragraphs with white-space: pre before choosing this setting.
Check a sentence split by inline links
For a navigation label made from an inline link followed by another word, inspect the exact space between them in the deployed markup. Removing a needed text-node space can join words even if the document still parses.
Use the conservative settings first. Compare a representative navigation line and a preformatted code sample before enabling optional whitespace changes across a site.
Common questions
Does the compressor shorten JavaScript inside a script tag?
Script text is preserved. Open the JavaScript Minifier to transform a separate script.
Why does a duplicate attribute produce an error?
Duplicate attributes can be discarded during HTML parsing. The compressor reports their source location so you can resolve the ambiguity before exporting.