XML Minifier

Client-sideNo sign-upFree

Strip indentation whitespace from XML while preserving mixed-content text exactly.

Quick facts

Category
Formatters & Beautifiers
Best for
Shrinking a config or payload for transmission without corrupting mixed-content text
Input
✗ Loading...
Minified output
// Fix the errors on the left to see minified output
Only whitespace-only text nodes used purely for indentation between element siblings are removed - real text content, including whitespace inside mixed content like <p>Hello <b>world</b>!</p>, is left exactly as written. Parses with the browser's native DOMParser, so malformed XML is rejected rather than silently mangled. Need the readable version instead? Use the XML Formatter & Validator.
In-content slot
Was this tool helpful?
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>&lt;p&gt;Hello &lt;b&gt;world&lt;/b&gt;!&lt;/p&gt;</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

  1. Paste your XML. Any well-formed document, including ones with mixed text/element content.
  2. DOMParser builds a real tree. The same parser xml-formatter uses checks well-formedness first.
  3. Indentation-only whitespace is removed. Whitespace-only text nodes between element siblings are dropped; real text is untouched.
  4. 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.

Explore more free tools

Formatters, converters, validators, and generators - all free and running entirely in your browser.

Browse more tools