Z

XML Formatter

Pretty-print and indent XML for readability, locally in your browser.

Runs in your browser — files never leave your device

Formatted

How it works

Paste XML and a re-indented copy appears instantly — there is no convert button; the formatter runs on every keystroke. It first collapses any whitespace sitting between tags (existing indentation and blank lines between elements are discarded), then starts a new line before each tag and indents nested elements by two spaces per level.

A minified <root><item>1</item></root> comes out as four lines: <root>, then <item>1 indented two spaces, then </item> and </root> each on their own line. As the example shows, an element whose content is plain text keeps the text on its opening-tag line, and the closing tag lands on the next line one indent level shallower — a cosmetic quirk of the lightweight algorithm, not a change to the XML itself.

Structural nodes are passed through untouched: the <?xml ?> declaration, comments, and DOCTYPE each get their own line without affecting depth, and self-closing tags such as <item id="1"/> do not open a new level. Attributes stay exactly as written.

This is a formatter, not a validator: nothing is parsed into a document tree, well-formedness is never checked, and mismatched or unclosed tags are indented on faith with no error message. It is built for reading machine-generated element trees — single-line SOAP and REST responses, RSS and Atom feeds, sitemaps, SVG exports, Maven POMs — and for pretty-printing two payloads into comparable shape before diffing them.

One caution: because whitespace between tags is collapsed and inline markup is split onto separate lines (<p>hello <b>world</b></p> becomes four lines), reformatting can alter whitespace-sensitive documents. Keep the original when exact spacing matters, such as content governed by xml:space.

Frequently asked questions

Does it validate the XML?
No. It is a pretty-printer, not a parser: it never builds a document tree or checks well-formedness, so mismatched or unclosed tags are indented on faith without any warning. Run the document through a real XML parser (xmllint, your IDE, or your language’s library) when you need validation.
What indentation rules does it apply?
Two spaces per nesting level. Whitespace sitting between tags is collapsed first, then every tag starts a new line and content nested inside a container element is indented one level deeper. The XML declaration, comments, and self-closing tags get their own lines without changing the depth.
Why is the closing tag of a text element outdented?
An element whose content is plain text keeps that text on the same line as its opening tag — <item>1 — and the matching closing tag lands on the next line one indent level shallower. It is a cosmetic quirk of the lightweight line-splitting algorithm and does not change what the XML means.
Can formatting change what my XML means?
In whitespace-sensitive documents, yes. Whitespace-only gaps between tags are discarded and rebuilt, and inline markup such as <p>hello <b>world</b></p> is split onto separate lines, which inserts line breaks into mixed content. Keep the original if the document relies on exact spacing, for example anything using xml:space="preserve".
Does it work on HTML?
Only if the markup is well-formed XML, like XHTML or SVG. Regular HTML allows unclosed tags such as <br> or <li>, which this formatter treats as opened containers, so everything after them drifts one indent level deeper. Use a dedicated HTML formatter for HTML.
Is my XML uploaded?
No — formatting is a pure string transformation that runs in your browser on every keystroke, with no network request. That matters when the payload contains tokens, keys, or customer data.