XML Formatter
Re-indent an unreadable XML document, or strip it back down to a single line — with the guarantee that whatever comes out says exactly what went in.
Input
XML- characters
- 0
- lines
- 0
- size
- 0 B
Options
About this tool
Most XML that arrives from an API or a build tool is a single line thousands of characters long. Indenting it is the difference between reading the structure and counting angle brackets, and it is the first thing worth doing before trying to find anything in the document.
This formatter changes presentation only. Whitespace between tags is layout and can be rewritten; whitespace inside an element is content and is left exactly as it was. That distinction matters more than it sounds — a formatter that trims text nodes will quietly turn a padded fixed-width field into a different value.
Documents that are not well-formed are rejected with the position of the problem rather than being reformatted. Tidy-looking output from broken input is the worst possible result, because it looks like the file is now fine.
How to use this tool
Paste XML, upload a file, or drop one onto the editor.
Choose Beautify or Minify, and set the indent width if you are beautifying.
Leave "Keep comments" on unless you specifically want them stripped.
Press Format, then copy or download the result.
Key features
- Beautify with a configurable indent width of 1 to 8 spaces
- Minify by removing only the whitespace between tags
- Comments preserved, or removed on request
- Text inside elements never trimmed or re-wrapped
- Attribute order and the XML declaration kept as written
- Well-formedness checked first, with the line and column of any failure
Example
Input — XML
<catalogue region="ap-northeast-2"><product sku="TENT-2P"><name>Two Person Tent</name><stock>34</stock></product></catalogue>Output — XML
<catalogue region="ap-northeast-2">
<product sku="TENT-2P">
<name>Two Person Tent</name>
<stock>34</stock>
</product>
</catalogue>Good to know
- Well-formedness is checked, but the document is not validated against a DTD or an XSD.
- CDATA sections are preserved as-is and are never re-indented, because their content is by definition not markup.
- Namespace prefixes are left alone; the formatter does not normalise or consolidate them.
Frequently asked questions
Why was my XML rejected instead of formatted?
The document is not well-formed — most often a tag that is never closed, closed in the wrong order, or an attribute value missing its quotes. The error names the line and column so you can go straight to it.
Does minifying change what the document means?
No. Only whitespace between a closing tag and the next opening tag is removed. Text inside an element is untouched, so mixed content keeps the spaces that belong to it.
Are my comments kept?
Yes by default. Turn off "Keep comments" if you want them removed — useful when the comments hold generated timestamps that create noise in a diff.
Is the file uploaded anywhere?
No. The parser runs in your browser and the document never leaves the tab. There is no request that could carry it.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.
Related tools
- XML ValidatorDeveloper ToolsCheck that XML is well-formed and get the line and column of the first error.XMLReport
- XML to JSONConvertersParse XML into JSON with configurable attribute, text-node and array handling.XMLJSON
- JSON to XMLConvertersTurn JSON objects and arrays into well-formed XML with a configurable root element.JSONXML
- HTML FormatterDeveloper ToolsIndent and clean up HTML markup with configurable wrapping.HTMLHTML
- XML to YAMLConvertersRead XML documents as YAML, with attributes and text nodes mapped explicitly.XMLYAML