The Util Box

XML Formatter & Beautifier

Free online xml formatter & beautifier for developers. Pretty-print XML with indentation. Fast and private.

Formatted XML
Paste XML above

Embed this tool

Copy and paste the code below into your website to embed this tool for free. An attribution link to The Util Box is required.

<iframe src="https://www.theutilbox.org/embed/xml-formatter" width="600" height="500" frameborder="0" style="border: none; max-width: 100%;" title="Free XML Formatter & Beautifier tool from The Util Box"></iframe>
<!-- Free tool by The Util Box — https://www.theutilbox.org/tools/xml-formatter -->
<a href="https://www.theutilbox.org/tools/xml-formatter">XML Formatter & Beautifier by The Util Box</a>

Frequently Asked Questions about XML Formatter & Beautifier

XML Formatter — Indent a Flattened Document

This XML formatter re-indents an XML document that has been flattened onto one line or badly indented. Paste it in and the tags come back nested with two spaces per level.

It is the tool for XML that arrived from a minifier, an API response, or a database column, where every element is jammed against the last.

How the Indentation Works

The document is first split wherever a tag is followed by a tag, then each piece is placed at the current depth. A closing tag reduces the depth before it is written, and an opening tag increases it afterwards — so a self-closing tag like <br/> sits at the level of its parent rather than pushing everything below it one level deeper.

The XML declaration and the document type declaration are recognised and left at the left margin, since neither may appear anywhere else in the document.

Honest Limits

  • The split is purely textual. A > inside an attribute value will be read as the end of a tag, and the formatting breaks from that point on.
  • Text content is not protected either. A CDATA section containing a < will confuse the split, since the tool does not track CDATA boundaries while splitting — it only re-indents afterwards.
  • Attributes are left exactly as they are, so a document with single-quoted attribute values keeps that style rather than being normalised.
  • It does not validate. A document with mismatched tags will be indented just as happily as a correct one — run it through the XML Validator afterwards.

Related Developer Tools

The formatting runs entirely in your browser — your XML is never uploaded.