On this page
Overview
Paste XML and get it compacted by removing whitespace-only text nodes that exist purely for indentation between element siblings - the kind of whitespace that only exists because a formatter put it there. Real text content is never touched: mixed content like <code><p>Hello <b>world</b>!</p></code> keeps its exact spacing, because that whitespace is part of the document’s actual meaning, not indentation. The input is parsed with the browser’s native DOMParser and re-serialized with XMLSerializer, so malformed XML is rejected with a clear error rather than mangled by a regex pass. Runs entirely client-side.
Best for: Shrinking a config or payload for transmission without corrupting mixed-content text
How to use this tool
- Paste your XML. Any well-formed document, including ones with mixed text/element content.
- DOMParser builds a real tree. The same parser xml-formatter uses checks well-formedness first.
- Indentation-only whitespace is removed. Whitespace-only text nodes between element siblings are dropped; real text is untouched.
- XMLSerializer re-serializes it. The compacted tree is turned back into an XML string.
Does this strip all whitespace, even inside text content?
No - only whitespace-only text nodes that sit purely between element siblings for indentation are removed. A text node that’s adjacent to elements but not entirely whitespace, like the space in <p>Hello <b>world</b>!</p>, is left completely untouched, because that spacing is meaningful content, not formatting. Getting this wrong is the most common way a naive XML minifier corrupts a document, so the distinction is deliberate here.
Why use this tool
Mixed content stays intact
Text alongside elements keeps its exact spacing - only pure indentation is removed.
Real parser, not regex
Malformed XML is rejected with a clear error instead of being blindly whitespace-stripped.
Before/after size
See the byte size reduction alongside the compacted output.
Client-side only
Nothing you paste is uploaded anywhere.
Frequently asked questions
No - that’s the specific case this tool is careful about. A whitespace-only text node is only removed when it sits between element siblings with no other content nearby; any text node that isn’t pure whitespace is left exactly as written, spacing included.
The XML Formatter goes the opposite direction - it adds indentation to make XML readable. This tool removes indentation-only whitespace to make it smaller. Both share the same well-formedness parsing underneath.