XML Formatter & Beautifier Online - Fast, Secure & Private
Updated
Format, validate, and beautify messy XML with custom indentation. Syntax errors are reported with the line where parsing failed. Runs in your browser; free.
What it does with tricky input
Each row is an automated test: the tool's own code runs on the input before every release, and the release stops if the result changes. Error text is what Chrome prints; Firefox and Safari word some errors differently. More on how we test.
| Case | Input | Result |
|---|---|---|
| Escaped charactersStay escaped. | Input<a><b>Tom & Jerry <3</b></a> | Result<a> <b>Tom & Jerry <3</b> </a> |
| A CDATA sectionKept byte for byte. | Input<a><b><![CDATA[<x> & y]]></b></a> | Result<a> <b><![CDATA[<x> & y]]></b> </a> |
| Comments | Input<a><!-- keep me --><b>1</b></a> | Result<a> <!-- keep me --> <b>1</b> </a> |
| The XML declaration | Input<?xml version="1.0" encoding="UTF-8"?><a><b/></a> | Result<?xml version="1.0" encoding="UTF-8"?> <a> <b/> </a> |
| Text with tags inside itLeft on one line, so no spaces are added to the text. | Input<p>Hello <b>big</b> world</p> | Result<p>Hello <b>big</b> world</p> |
| Spaces around a text valueSpaces at the ends of a text value are trimmed; spaces inside are kept. | Input<a><b> two spaces </b></a> | Result<a> <b>two spaces</b> </a> |
| A closing tag that does not match | Input<a><b></a> | ResultError: XML parsing error: line 1, column 7: Expected closing tag 'b' (opened in line 1, col 4) instead of closing tag 'a' |
Key Features
- ✅ Auto-indentation
- ✅ Line numbers
- ✅ Error detection
- ✅ File upload
- ✅ Copy/Download
How to Use
- Copy or paste your XML content
- Select your preferred indentation size (2, 4 spaces, or tabs)
- Click Format to apply formatting
- Preview the formatted XML
- Pick an indentation size (2 or 4 spaces)
- Copy the output or download as .xml file
- Use in your application or editor
- Version control the formatted XML for consistency
Expert FAQ
- Unlike JSON, XML whitespace can be meaningful. Won't re-indenting break mixed content?
It can, which is why this formatter keeps the order of text and child tags inside a mixed-content element (e.g. <p>Click <a>here</a> to continue</p>), but it places each text run and child tag on its own indented line and trims the spaces around them. If that whitespace matters, use the XML Minifier, which keeps text runs exactly as written. Pure "data" XML (config files, API payloads) reformats freely since whitespace between tags is almost always insignificant there. - What happens to CDATA sections and comments?
Both are preserved byte-for-byte inside their delimiters (<![CDATA[ ... ]]> and <!-- ... -->) — the formatter never reflows the contents of a CDATA block, since that section is explicitly there to hold pre-formatted or escaped content (embedded HTML, JS snippets, etc.) that must survive unchanged. - Does it normalize self-closing tags like <br/> vs <br></br>?
Yes — because the formatter fully reparses and rebuilds the document, both <br/> and <br></br> are normalized to the same explicit open/close tag pair in the output, regardless of which form was in the source. Some XML consumers (older parsers, certain SOAP toolkits) are inconsistent about treating the two as equivalent, so silently "normalizing" them is a common source of formatter-introduced regressions that this tool deliberately avoids. - My XML has a DOCTYPE and processing instructions (<?xml-stylesheet ...?>) — will formatting strip them?
The prolog and any processing instructions are kept in place, but the DOCTYPE declaration itself is dropped during formatting, since the tool fully reparses and rebuilds the document rather than only re-indenting the original markup. Stripping these is a real risk with some "quick" online formatters and can silently change how a downstream XML processor interprets encoding or applies a stylesheet.
Technical Details
Formatting XML is meaningfully harder to get right than formatting JSON, because JSON whitespace is never semantically significant while XML whitespace sometimes is. A naive formatter that blindly re-indents every tag will corrupt documents containing mixed content (text interleaved with inline elements, e.g. legal or documentation XML, XHTML fragments, DocBook) by inserting newlines and spaces into what was meant to be continuous text. This formatter detects mixed-content nodes and leaves them untouched, while still fully re-indenting "data-style" XML (the common case: SOAP envelopes, RSS/Atom feeds, config files, WSDL, Android/Maven XML) where inter-tag whitespace carries no meaning. CDATA blocks, comments, the XML prolog, and DOCTYPE declarations are preserved verbatim rather than reflowed or stripped — all are common places where lossy formatters introduce subtle bugs. Attribute handling is also configurable: documents with many attributes per element (common in Android layout XML or MSBuild project files) can wrap one attribute per line for reviewable diffs, while simpler documents keep attributes inline. If your XML fails to format cleanly, run it through the XML Validator first — the formatter assumes well-formed input and will surface the same syntax error rather than guessing at a malformed document's intended structure.