XML Formatter
Format XML documents.
About this tool
Paste XML and get it back with each element on its own line, indented by nesting depth. It is a quick readability tool that works on the text and does not validate the document.
How to use
How it works
The text is split wherever one tag ends and the next begins, and each tag is placed on its own line. The indent grows after an opening tag and shrinks at a closing tag. Self-closing tags and comments do not change the depth.
Worked example
A compact document
- Input
- <root><item id="1"><name>A</name></item><item id="2"/></root>
- Output
- <root> <item id="1"> <name>A</name> </item> <item id="2"/> </root>
- Walkthrough
- item is indented under root and name under item. The self-closing item stays at the same level.
Limitations
- It does not check that the XML is well-formed.
- An <?xml...?> declaration line is counted as an opening tag, so the rest of the document is indented one level extra.
- Single-letter element names (such as <a> or <b>) are not indented as parents.
- Mixed content (text between tags) is split across lines.
Questions
How do I pretty-print XML?
Does it validate my XML?
Why is everything indented one level too far?
Can I format SVG or HTML with it?
Features
- Indents by nesting depth
- Self-closing tags handled
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
TypeScript in 100 Seconds
Fireship
Typed JSON payloads show up constantly next to format/validate tools.
Watch on YouTubeSQL Tutorial - Full Database Course
freeCodeCamp.org
JSON often lands next to SQL exports when debugging data pipelines.
Watch on YouTube
- Introducing JSON
json.org
Canonical JSON grammar—handy when a formatter rejects a trailing comma.
- MDN Web Docs
MDN
Primary reference for web APIs these developer tools touch.