Skip to content
snip tools

XML formatter and beautifier

Validate and pretty-print XML with clean indentation. Runs in your browser.

Runs 100% in your browser
 

How to format XML

  1. Paste your XML. Paste a minified or inconsistently-indented document into the input.
  2. Pick an indent. Choose 2 spaces, 4 spaces or a tab.
  3. Read or copy the result. Any well-formedness error is reported; otherwise copy or download the formatted XML.

Well-formed vs valid

XML has two separate notions of "correct," and it's worth knowing which one this checks. Well-formed means the syntax is right: every tag is closed, tags nest properly, there's a single root, and special characters are escaped. Valid means the document also conforms to a schema (a DTD or XSD) that dictates which elements are allowed where. This formatter enforces the first — it parses with the browser's XML engine and won't format a document that isn't well-formed — but it can't check the second, because that needs your schema. In practice the well-formedness check catches the breakage you hit most: a mismatched or unclosed tag.

The whitespace caveat

Re-indenting adds whitespace between elements, and for the data-style XML most people format — config files, SOAP envelopes, RSS, exports — that whitespace is insignificant and the meaning is untouched. The exception is mixed content, where text and inline elements sit side by side (think prose with <em> tags); there, whitespace can matter, so reformat such documents with a little care. To keep value-heavy XML readable, this tool deliberately keeps a text-only leaf element on a single line rather than splitting its content onto its own row.

Reading and producing XML

Formatting is usually the first step in debugging an unfamiliar payload — once the structure is visible, the problem usually is too. If you're generating XML from data rather than tidying existing markup, the JSON to XML converter builds a well-formed tree from JSON, and the JSON formatter does the equivalent job for JSON documents.

Frequently asked questions

What does the XML formatter do?
It parses your document to confirm it's well-formed, then re-indents it so the nesting is visible. Leaf elements that contain only text are kept on one line, so a value-heavy document stays compact rather than exploding every <name>Ada</name> across three lines.
Will it tell me if my XML is broken?
Yes — it uses the browser's built-in XML parser, so mismatched or unclosed tags, stray characters, a missing root and other well-formedness errors are caught and reported instead of producing garbled output.
Does it validate against a DTD or XSD schema?
No. It checks well-formedness (is the syntax correct?), not validity (does the document match a specific schema?). A file can be perfectly well-formed XML yet invalid against its XSD — schema validation needs the schema and is a separate step.
Could re-indenting change my document's meaning?
For data-style XML — config files, API payloads, exports — no; the added whitespace sits between elements where it's insignificant. The one place to be careful is mixed content (text and inline elements together, as in prose markup), where whitespace can be significant. CDATA sections and text content are preserved as-is.
Which indent should I use?
Two spaces, four spaces or a tab — match the convention of the project the file lives in so version-control diffs stay clean.
Is my XML uploaded?
No. Parsing and formatting both happen in your browser; the document never leaves the page.