About XML Formatter
XML that has travelled through an API or a build step usually arrives on one line, which is efficient for a machine and unreadable for a person trying to see what a document actually contains. Formatting restores the structure.
The common way to build an XML formatter is to parse the document into an object and serialise a new one back out. That is simple, but it is lossy: comments disappear, because there is nowhere in a parsed object model to keep them, and so do processing instructions and the original attribute order. This formatter instead works directly on the document's own tags, moving only whitespace — so a comment left as a note for the next developer, or a CDATA block holding literal markup, survives exactly as written.
Validation is delegated to a dedicated XML parser rather than a hand-rolled check, since the well-formedness rules — matching tags, a single root element, correctly escaped entities — have edge cases a quick regex reliably gets wrong.
How to format XML
Paste your XML
Minified, hand-written, or exported from another tool.
Choose an operation
Format to indent it, minify to compact it, or validate to check it.
Set the indent
Two spaces, four spaces, or a tab.
Copy or download
Take the result to your clipboard or save it as a .xml file.
What survives formatting
- Comments (<!-- ... -->) — kept in place, content untouched.
- CDATA sections (<![CDATA[ ... ]]>) — kept as a single block, even when the content contains characters that look like tags.
- Processing instructions (<?...?>), including the XML declaration.
- Attribute order — never reordered, unlike a round trip through a parsed object.