XML formatter
Paste XML to indent it neatly, squeeze it onto one line, or check it is valid. Errors come with the line, the column and a plain explanation.
- 100% free
- Runs in your browser
- No uploads
- Runs on your deviceEvery tool works directly in your browser. No files are uploaded.
- Your privacy mattersYour files never leave your device, so there's nothing for us to store.
- No limitsUse any tool as much as you need. No daily caps, no waiting.
- Completely freeNo signup and no trial to cancel. Ads keep the tools free.
How to format XML
- Paste XML or open a file. .xml, .svg, .xsd, .rss and similar files open directly, or drop them on the box.
- Choose the layout. 2 or 4 spaces or tabs for reading, Minify for a single line.
- Fix any error. The message gives the line and column, and Go to the error puts your cursor there.
- Copy or download. Download saves a .xml file named after the file you opened.
Common XML errors and fixes
| Error | Wrong | Right |
|---|---|---|
| Tags closed in the wrong order | <b><i>x</b></i> | <b><i>x</i></b> |
| Unquoted attribute | <item sku=A-7> | <item sku="A-7"> |
| Bare ampersand | Fish & chips | Fish & chips |
| Two root elements | <a/><b/> | <root><a/><b/></root> |
| Space before the declaration | <?xml version="1.0"?> | Nothing before <?xml, not even a blank line |
| Unclosed empty tag | <br> | <br/> |
This order has three of these mistakes. Load it and fix them one at a time.
How the formatter works
The XML is read by a strict parser that runs in your browser and reports the first problem with its exact position, the same way in every browser. Once it reads cleanly, the browser's own XML parser checks it a second time, which also catches namespace prefixes such as xs: used without an xmlns:xs declaration.
Each element goes on its own line, indented one level deeper than its parent. An element that holds only text stays on one line, like <title>Midnight Rain</title>, and empty elements keep the form you wrote: <tags/> or <tags></tags>.
Frequently asked questions
Does it validate XML against a schema (XSD or DTD)?
No. It checks that the XML is well-formed: one root element, every tag closed in the right order, attributes quoted and not repeated, and entities written correctly. Schema validation, such as whether an element is allowed in a certain place, needs the XSD and a validating parser.
Will formatting change my data?
Only whitespace between tags changes. Text, attribute values, entities such as &, CDATA sections and comments are kept exactly as written. Elements that mix text and child elements, like <p>Hello <b>world</b></p>, and elements with xml:space="preserve" are left on one line untouched, because adding spaces there would change the text.
Why is an error?
XML only defines five named entities: & < > " and '. and © come from HTML. Use the numeric form instead,   for a non-breaking space and © for ©, or declare the entity in a DOCTYPE.
Can I format SVG, RSS, sitemaps or Android layouts?
Yes. They are all XML, so any of them formats and validates here. Open the file with Open file or drop it on the box.
What does Minify remove?
Line breaks and indentation between tags, and spaces at the start and end of text. With Keep comments off, comments are dropped too. The result is the smallest equivalent file, handy for config values and API payloads.