XML Formatter

Pretty-print and validate XML documents with indentation.

Runs locally in your browser. Your input is not uploaded or stored. You can verify this in your browser’s network panel.

What does this tool solve?

Paste minified or hand-edited XML, choose whether text content collapses onto one line, and set the indentation from 0 to 10 spaces.

What examples should you start with?

Format a nested document

Input

<root><item id="1">text</item></root>

Output

<root>
  <item id="1">text</item>
</root>

Mismatched tags

Input

<a><b></a></b>

Output

Error: Mismatched tag: expected </b> but found </a>.

How does it work?

The formatter tokenizes tags, text, comments, CDATA sections, and declarations; an explicit stack tracks nesting and verifies that every closing tag matches the most recent open tag.

Elements containing only text collapse onto one line for readability; everything else indents by depth.

What are the edge cases and limits?

  • This is a structural formatter, not a full validating parser — DTD validation and namespace checks are out of scope.
  • Whitespace-only text nodes are trimmed; significant mixed content whitespace may be normalized.
  • DOCTYPE declarations pass through as-is and are not interpreted.

Technical reference

Related tools