← All tools/Minifiers/Code/XML Formatter
XML Formatter
Paste tangled XML and get a neatly indented version, two spaces per level — checked for errors as it formats.
Nothing leaves your browser — the formatting happens on this page. Invalid XML is reported quietly instead of producing broken output.
Formatted XML
Input vs formatted size
How it works
1. Check the XML with the browser’s own parser — invalid XML is reported, not reformatted. 2. Remove spacing between tags. 3. Re-indent from scratch: 2 spaces per nesting level. 4. Elements that hold only text stay on one line.
The tool works in four steps. First it checks the XML with the browser’s own parser — invalid XML is reported, not reformatted, because guessing at a broken document would hide the error. Then it removes the spacing between tags, so the original layout cannot interfere. Next it re-indents from scratch, adding two spaces per nesting level, so a child sits two spaces to the right of its parent. Finally, elements that hold only text stay on one line, which keeps short values readable instead of spreading them over three lines. Tag names, attributes, text and the nesting structure are left exactly as you wrote them; only whitespace between tags changes.
Worked example: “<root><a>1</a><b>2</b></root>” becomes:
<root>
<a>1</a>
<b>2</b>
</root>
— the two child elements are indented one level (2 spaces), and each text-only element stays on a single line.
Second worked example: take “<school><class><name>Class 10 A</name><students>42</students></class></school>” — one line holding a school, a class, and two values. The parser checks it first, then the formatter re-indents it into six lines: <school> at level 0, <class> indented 2 spaces, <name>Class 10 A</name> and <students>42</students> indented 4 spaces, then the closing tags back out again. Each text-only element stays on a single line, so the values are easy to scan.
Frequently asked questions
What happens if my XML is invalid?
The page says so in plain words — for example, that a closing tag may be missing — and leaves the output empty, rather than guessing at a broken result. Fix the error and it formats straight away. Check the very end of the document first, because an unclosed tag near the end is the most common cause, and the parser often reports the problem far from where it started.
Does it change my XML’s meaning?
No. Only whitespace between tags changes. Tag names, attributes, text and the nesting structure are left exactly as you wrote them. A parser reading the formatted output sees the same elements in the same order with the same values, so the file works exactly as it did before formatting.
Why 2-space indentation?
Two spaces per level is the most common style for XML and keeps deeply nested documents readable without pushing them far to the right on a narrow screen. Four spaces would be clearer for shallow documents, but an XML file nested six levels deep would already sit 24 spaces in, which wastes most of a phone screen.
Does my XML leave my browser?
No. Parsing and formatting run entirely in JavaScript on this page, and nothing is uploaded or stored anywhere. You can safely paste XML from a private system or a work config file, because the text never leaves your computer. Closing the tab removes it from the page.
Can it handle large documents?
Yes — pastes of thousands of lines format in a moment. Very large documents may take a second, but the result is the same neatly indented XML. If a file is too big to paste comfortably, split it at a top-level element, format the pieces, and put them back together in the same order.
Common mistakes
The most common mistake is pasting HTML and expecting it to format. HTML allows unclosed tags and loose syntax that XML forbids, so the parser rejects it — a missing closing tag or a bare & in text will stop the whole document. If your file is HTML, use an HTML formatter instead; this tool only accepts well-formed XML, and that strictness is what keeps the output trustworthy.
A second mistake is treating the formatted output as proof that the data is right. Formatting only fixes the layout; it cannot tell you that a pincode is wrong, a price is in the wrong currency, or an element is in the wrong place. Read the values after formatting, especially the first and last elements, and check any numbers against the source before you save the file or send it on.
Tell us what you think
Loving this tool, or stuck on something? Tell us — it takes a minute.
We’ll only use your name and email to reply if needed. The tool and page are filled in for you.