XML Formatter
Pretty-print or minify XML, with well-formedness checking.
Enter some XML on the left to see the result here.
What is XML Formatter?
XML (eXtensible Markup Language) is a markup language defined by the W3C that uses nested, paired tags to structure data and metadata, and underlies formats such as SOAP, SVG, RSS, and many configuration files. An XML formatter parses a document and re-emits it with consistent indentation and line breaks so the tag hierarchy is easy to follow, or strips all non-essential whitespace to minify it for transfer. This tool checks well-formedness — every opening tag must have a matching closing tag in the right order — and reports the specific offending tag rather than a generic failure, while leaving comments, CDATA sections, and the XML prolog untouched. It does not validate a document against an XSD or DTD schema; it only checks that the XML is syntactically well-formed.
How to Use XML Formatter
- Paste your XML into the input box, or drag a .xml file onto it.
- Switch between "Format" (pretty-printed with indentation) and "Minify" (whitespace stripped) using the tabs.
- In Format mode, choose a 2- or 4-space indent width.
- Click "Copy" to copy the result, or use the expand button for more working room on large documents.
Examples
Format
Input: <root><child>text</child></root>
Output: <root> <child>text</child> </root>
Minify
Input: <root> <child>text</child> </root>
Output: <root><child>text</child></root>
Self-closing tags stay on their own line
Input: <root><item/><item/></root>
Output: <root> <item/> <item/> </root>
Common Mistakes
- Confusing XML formatting with XML validation against a schema — this tool checks well-formedness, not conformance to a specific XSD/DTD.
- Assuming unescaped `&`, `<`, or `>` inside text content is fine — valid XML requires these to be escaped as &, <, > even though many hand-written XML snippets skip it.
- Forgetting that XML (unlike HTML) is case-sensitive and requires every tag to be explicitly closed — <br> alone is not valid XML, it must be <br/>.
Why Use This Tool
- Catches unclosed and mismatched tags with a specific error naming the offending tag, not just "invalid XML".
- Correctly handles comments, CDATA sections, the XML prolog, and self-closing tags without mangling them.
- Format and Minify in one tool, with a configurable indent width.
- Runs entirely client-side — your XML is never sent to a server.