Format XML
Indent it, or strip it back down.
Everything is processed in this tab. Nothing you paste is sent anywhere.
Every tool runs entirely in your browser. Your files are never uploaded to a server.
Formatting XML indents each element by its depth so the structure is visible. It changes only whitespace between tags — the document parses identically either way.
How to use XML Formatter
- Paste your XML. A fragment, a document, a config file or an API response.
- Choose indent or minify. Indent for reading, minify for transmission.
- Copy the result. CDATA sections and comments come through untouched.
About formatting XML
XML formatting is a readability operation. The parser does not care how a document is laid out — whitespace between elements is insignificant in most contexts — so indenting by depth is safe and makes structure visible in a way a single-line document never is. That said, "most contexts" is doing real work in that sentence, and it is where formatters go wrong. Two constructs must survive untouched. A CDATA section exists specifically to hold characters that would otherwise be parsed as markup, so everything inside it is data and reindenting it changes the document. Comments are the same in practice, since their content is frequently meaningful to whoever left them. Both are lifted out before any whitespace manipulation and restored afterwards. Mixed content is the subtler case. An element containing both text and child elements — common in document-oriented XML like DocBook or XHTML — has whitespace that genuinely affects rendering, because the text nodes around the children are part of the content. Pushing text onto its own indented line inserts whitespace that was not there. Keeping short text content on the same line as its tags avoids the worst of it and is also more readable. The tag-balance check here counts rather than parses, which catches the common error of an unclosed element without pulling a parser into a page that ships no dependencies. It is not validation: a document can balance perfectly and still violate its schema.
Frequently asked questions
Does indenting change the document?
Why is CDATA left alone?
What is the difference between XML and HTML here?
Does this validate against a schema?
Should I minify XML for transmission?
Last updated