XML Formatter & Validator
Format, prettify, and validate XML instantly in your browser. No upload required — completely private and free.
Drag & Drop an XML file here
Supports .xml files. Or paste your XML in the area above.
Format, prettify, and validate XML instantly in your browser. No upload required — completely private and free.
Supports .xml files. Or paste your XML in the area above.
XML formatting indents nested elements so the document hierarchy becomes visible. Compact XML — everything on one line — is technically valid and useful for transmission, but unreadable for humans. Formatted XML adds line breaks between elements and indents children inside their parents, making it scannable, diffable, and editable by hand.
This formatter parses the input using DOMParser to confirm well-formedness, then walks the resulting DOM to emit indented output. Comments, processing instructions, and CDATA sections are preserved. Self-closing tags (those without children) are kept compact on a single line; tags with children are spread across multiple lines with the children indented.
Two-space indentation is the default, matching the most common XML convention. The formatter is conservative about reformatting: existing structure is preserved, only whitespace between elements changes. The data round-trips through any XML parser identically before and after formatting.
Compact XML is unreadable. SOAP responses, RSS feeds, and many configuration files arrive as single-line XML that is technically valid but practically opaque. Formatting reveals the document structure, lets you locate specific elements, and makes diffs in version control meaningful.
Formatting also serves as a validity check. If the XML fails to parse during formatting, the error message identifies the problem — usually unclosed tags, mismatched element names, or invalid characters. Catching XML errors before sending to a strict consumer saves debugging time.
Paste XML, click format.
DOMParser produces an XML DOM. The formatter walks the tree depth-first, emitting opening tags, indented children, and closing tags. Element attributes are preserved on the opening tag; attribute order matches the source.
Significant whitespace inside text nodes is preserved — the formatter cannot safely change content whitespace because it may be meaningful (XML space preservation rules differ across schemas). Only whitespace between elements changes.
Self-closing elements (no children) emit as <tag attr="val"/>. Elements with only text content emit as <tag>text</tag>. Elements with element children emit on multiple lines with indented children. CDATA sections, comments, and processing instructions emit with their original delimiters and content.