XML Formatter

Format XML documents.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

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

1
Step 1
Paste the XML.
2
Step 2
Press Run.
3
Step 3
Copy the indented XML.

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?
Paste it and press Run to get indented output.
Does it validate my XML?
No. It only changes whitespace.
Why is everything indented one level too far?
The XML declaration line is treated as an opening tag. Remove the declaration, format, then add it back.
Can I format SVG or HTML with it?
SVG works because it is XML. HTML with unclosed tags such as <br> or <img> may be indented wrongly.

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 YouTube
  • SQL 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.