XML Formatter & Minifier
Format or minify XML - free, no upload.
What this tool does
Paste your XML and choose Format for clean indentation or Minify for the smallest valid representation - invalid XML shows the parser's own error.
Formats XML with clean, consistent indentation based on real element nesting.
Minifies XML by removing insignificant whitespace between tags.
Preserves comments, CDATA sections and attributes correctly in both modes.
Keeps the leading XML declaration (like <?xml version="1.0"?>) exactly as written, ahead of the formatted or minified body.
Shows input and output character counts and the percentage size change, so you can see exactly how much minifying saved.
How to use it
- Paste your XML.
- Choose Format or Minify.
- Copy or download the result.
Why use this formatter
XML from services is often a single line. Formatting shows the nesting, and minifying reduces size for transport.
Why we built it
We built the XML formatter on the browser's real XML parser, not a regex indenter, so attributes, comments and CDATA survive. Convert with the XML to CSV converter and the JSON to XML converter.
Who this tool is for
- Developers reading feeds and configs
- Analysts inspecting exports
- Students learning XML
When to use it
- Reading API or config XML.
- Checking well-formedness.
- Minifying for transmission.
- Reviewing structure.
Why a real parser instead of a regex indenter
XML has enough structural nuance that guessing at nesting from text alone goes wrong.
Correctly re-indenting XML means knowing exactly which opening tag a closing tag belongs to, whether an empty element should self-close, and how to handle attributes, comments and CDATA sections without corrupting them. A text-based indenter that just counts angle brackets gets this wrong on real-world XML often enough to matter. This tool parses the document with the browser's built-in XML parser first, so the formatted or minified output is built from the actual document structure, not a guess at it.
Why whitespace is cosmetic, but a formatter still catches real errors
Indentation carries no meaning in XML's data model, but producing it at all requires the document to actually parse.
The line breaks and indentation between tags aren't part of the data an XML document represents - a document squeezed onto one line and the same document spread across a hundred indented lines parse to the identical structure, so formatting or minifying never changes what a program reading that XML sees. But turning either one into the other requires the parser to make sense of the whole document first, which is why running minified or hand-edited XML through a formatter doubles as a correctness check: an unclosed tag, a mismatched closing tag, a second root element, or an attribute missing its closing quote all stop the browser's parser cold and surface as an error message - the kind of mistake that's easy to miss scanning a dense, minified line by eye but impossible for a real parser to overlook.
What you give it, and what you get back
| Item | Details |
|---|---|
| Input | XML. |
| Mode | Format or minify. |
| Output | Indented or compact XML, or the parser error. |
Issues you may run into
| What you see | Why it happens | What to do |
|---|---|---|
| An error is shown | The XML is not well-formed. | Fix mismatched or unclosed tags. |
| DOCTYPE is missing | It is not preserved. | Add it back if required. |
| Whitespace-sensitive content changes | Spacing may matter. | Check mixed-content blocks. |
Assumptions and limitations
- Invalid or non-well-formed XML can't be formatted - the parser's own error message is shown instead.
- Processing instructions other than the leading XML declaration, and DOCTYPE declarations, are not preserved.
Frequently asked questions
How do I format XML online for free?
Paste your XML and choose Format - it's re-indented based on real element nesting.
How do I minify XML?
Paste your XML and choose Minify to remove whitespace between tags.
Does this handle comments and CDATA sections?
Yes - both are preserved correctly in Format and Minify modes.
Does this validate my XML?
It reports whether the XML is well-formed, since that's required just to parse it - it doesn't validate against a schema.
Is my data uploaded anywhere?
No. Everything happens in your browser.
Does formatting change the actual data in my XML?
No - line breaks and indentation between tags aren't part of the data itself; actual text content, attributes, comments and CDATA sections are untouched.
What kind of XML errors will this catch?
Anything that stops the browser's XML parser from succeeding - unclosed or mismatched tags, more than one root element, or a malformed attribute - shown as the parser's own error message.