XML Formatter
Format, minify, and validate XML — copy and paste the result.
This free online XML formatter pretty-prints or minifies XML, with adjustable indentation. Comments, CDATA sections, and the XML declaration are preserved exactly. Invalid XML shows a clear parser error instead of a broken result. No signup required, runs entirely in your browser.
Mode
Indent
Preserved as-is
- <?xml version="1.0"?>
- XML declaration
- <!-- comment -->
- Comments
- <![CDATA[ ... ]]>
- CDATA sections
What does an XML formatter do?
An XML formatter takes XML text and re-outputs it with consistent, readable indentation — turning a dense, single-line SOAP response or config file into something you can actually scan. This tool validates the input first using your browser's native XML parser, so if your document isn't well-formed, you get a clear error instead of a broken or empty result.
Format vs minify
Format (pretty-print) adds indentation and line breaks so nested elements are easy to read — pick 2 spaces, 4 spaces, or a tab. Minify does the opposite: it strips every insignificant whitespace-only text node between tags, producing the smallest possible valid XML — useful when you're about to send the payload over the network and don't need it to be human-readable.
What gets preserved
Comments (<!-- ... -->), CDATA sections (<![CDATA[ ... ]]>), and the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) are all kept exactly as written in both modes. Only whitespace between tags — the parts that don't affect the document's meaning — is added or removed.
Common XML syntax errors
- Mismatched tags —
<a><b></a></b>is invalid; every opening tag must close in the reverse order it opened. - Unclosed elements — every
<tag>needs a matching</tag>or a self-closing<tag/>. - Multiple root elements — a well-formed XML document can only have one top-level element; everything else must be nested inside it.
- Unescaped special characters — a raw
&or<inside text content must be written as&or<.
This tool uses your browser's native XML parser, so error messages match exactly what your browser's engine reports.
Working with other structured data?
See the JSON Formatter for JSON, or the Hex to Decimal Converter and UUID Generator for other developer utilities.
Frequently asked questions
<?xml version="1.0"?>) are all kept exactly as written — only whitespace between tags is added or removed depending on the mode.