XML Formatter
Indent and beautify XML without rewriting your document - comments, CDATA, and attribute order are preserved.
Conversion payloads stay in this browser tab and are never placed in page URLs - see how local processing works. Privacy-safe analytics record only the tool, outcome, and a coarse input-size bucket. Press Cmd/Ctrl + Enter to convert.
How to Format XML
Paste XML - a SOAP envelope, an RSS feed, a pom.xml, an Android layout, a sitemap - and the formatter indents it two spaces per level. Elements whose only content is text stay on one line so record-style documents remain compact and readable. Use the Minify option to reverse the process before storing or transmitting the document.
Formatting Rules Applied
These are the only transformations performed.
| Input | Output | Note |
|---|---|---|
| <a><b>1</b></a> | <a> <b>1</b> </a> | Child elements get their own line |
| <b>text</b> | <b>text</b> | Text-only elements stay inline |
| <!-- note --> | <!-- note --> | Comments preserved |
| <![CDATA[ raw ]]> | <![CDATA[ raw ]]> | CDATA content untouched |
| <x b="2" a="1"/> | <x b="2" a="1"/> | Attribute order never sorted |
Formatting Is Not Schema Validation
A formatted document is well-formed, which means its tags nest and pair correctly. It does not mean the document matches a DTD, XSD, or RELAX NG schema - that check needs the schema itself. Use the XML validator for a well-formedness report with a structural summary, and treat schema conformance as a separate step in your build.
Frequently Asked Questions
Does formatting change my XML document?
Only its whitespace. This formatter re-indents the existing markup instead of parsing it into a data model and rebuilding it, so comments, CDATA sections, processing instructions, the DOCTYPE, and the original attribute order all survive. Parse-and-rebuild formatters routinely drop those.
Can it minify XML as well as indent it?
Yes. Tick "Minify output" to strip whitespace-only text between elements and emit the document on a single line. Text content inside elements is never altered, because in XML that whitespace can be significant.
What happens with invalid XML?
Formatting stops and you get the first well-formedness problem with its line and column - an unclosed tag, a mismatched end tag, an unquoted attribute, or a bad entity. Nothing is silently repaired.
Is my XML uploaded anywhere?
No. Validation and formatting run in this browser tab using JavaScript. The document is never sent to a server and never placed in a shareable URL.