XML Formatter & Beautifier
Paste or open XML to indent it with 2 spaces, 4 spaces or tabs, minify it, or check it for syntax errors with the exact line and column. Your XML is processed in your browser and never uploaded.
Paste XML here, drop a file, or open one from your device.
.xml, .svg, .xsd, .xsl, .rss, .kml, .gpx, .plist and other XML text files up to 50 MB.
Press Format (or Ctrl/⌘ + Enter) to indent your XML. Syntax errors are shown here with their line and column.
Next steps
Quick start
- 1
Paste or open your XML
Paste XML into the editor, drop a file on it, or choose Open file. Try a sample if you just want to see how it works.
- 2
Choose the indentation
Pick 2 spaces, 4 spaces, or tabs.
- 3
Press Format
The XML is checked first. If it is malformed, the line and column of the first error are shown and the cursor jumps there.
- 4
Copy or download
Copy the result to the clipboard or download it as formatted.xml.
Data stays on your device
Parsing and formatting run in your browser. Opened files are read locally and are not uploaded.
Shortcuts
Format XML into readable, indented elements, minify it, or check that it is well-formed. The formatter changes only whitespace between tags; text, CDATA, comments and attribute values are left exactly as they are. It checks XML syntax, not XSD or DTD schemas.
2, 4 or tab
Indentation
Line + column
Errors
In your browser
Runs
Format with your indentation
Indent with 2 spaces, 4 spaces or tabs. Formatting the result again changes nothing.
Errors with line and column
Malformed XML is reported with the line, column and a plain explanation, and the cursor jumps to it.
Your data stays the same
Text, CDATA, comments, processing instructions, namespaces and entity references are preserved exactly.
Minify
Remove whitespace between tags for a compact document without touching text values.
Private
Nothing is uploaded. The XML is parsed and formatted in your browser.
How do I beautify XML online?
Paste the XML into the editor (or open a file), choose 2 spaces, 4 spaces or tabs, and press Format. Each nested element goes on its own indented line. Copy the result or download it as formatted.xml.
Is my XML uploaded to a server?
No. Parsing and formatting run in JavaScript in your browser tab. Files you open are read locally and the XML is never sent to ChatDB.
Does the XML formatter validate my XML?
It checks that the XML is well-formed: tags are closed and nested correctly, there is one root element, attributes are quoted and not repeated, and every & starts a valid entity or character reference. It does not validate against an XSD schema or DTD, so a well-formed file can still be rejected by an application that expects particular elements.
Where is the error in my XML?
When the XML is malformed, the formatter shows the line and column of the first problem with a short explanation, for example a closing tag that does not match, and moves the cursor to it. Fix it and press Format again to find the next one.
Does formatting change my data?
Only whitespace between tags and inside tags changes. Text, attribute values, comments, CDATA sections, processing instructions, the DOCTYPE and entity references such as & are kept exactly as written. Inside elements that mix text with child elements, and under xml:space="preserve", the content is left exactly as written because its whitespace can be part of the data.
How do I minify XML?
Press Minify to remove the whitespace between tags. Whitespace inside text is data, so it is kept; a document whose text spans several lines stays on several lines.
Why does my & cause an error?
In XML a literal ampersand must be written as &. HTML names such as are not defined in XML either: use   or declare the entity in a DOCTYPE.
How large an XML file can I format?
Files up to 50 MB can be opened. In our tests a 28 MB file with 1.5 million elements formatted in under a second in desktop Chrome; typing in the editor gets slower at that size.
Format XML: before and after
API responses, SOAP messages, sitemaps and exported config files often arrive as one long line. Format puts each nested element on its own line. Elements that hold text stay on one line, so values are not split up.
Before
<order id="42"><!-- rush --><item sku="A-1">Notebook</item><qty>2</qty><note><![CDATA[Leave at door & ring]]></note></order>After Format (2 spaces)
<order id="42">
<!-- rush -->
<item sku="A-1">Notebook</item>
<qty>2</qty>
<note><![CDATA[Leave at door & ring]]></note>
</order>What the formatter changes, and what it leaves alone
- Changes: whitespace between tags, and line breaks or extra spaces between attributes inside a tag (attributes end up separated by single spaces).
- Keeps exactly: text, attribute values and their quote style, namespace prefixes, comments, CDATA sections, processing instructions such as
<?xml-stylesheet?>, the DOCTYPE, and references like&or©. - Does not reindent: elements that mix text with child elements (XHTML paragraphs, DocBook) and elements under
xml:space="preserve", because adding whitespace there would change the content.
The result is the same document: apart from whitespace between tags, parsing the formatted XML gives the same elements, attributes and text as the original. Minify does the reverse and removes whitespace between tags, keeping whitespace inside text.
Fix common XML errors
Format, Minify and Check syntax all check that the XML is well-formed first. The first error is shown with its line and column. These are the messages people hit most often:
| Message | How to fix it |
|---|---|
| Expected </item> … but found </items> | The closing tag must match the opening tag exactly, including case. |
| A bare "&" is not allowed | Write & as &, or put the text in a CDATA section. |
| The entity " " is not defined | XML only predefines & < > " '. Use   for a non-breaking space. |
| Only one root element is allowed | Wrap the elements in a single parent element. |
| Text is not allowed before the root element | Remove stray text, such as a log prefix or a byte-order mark pasted as text, before the first tag. |
| The XML declaration must be the very first thing | Move <?xml version="1.0"?> to the top, or delete the second one when two files were pasted together. |
Well-formed is not the same as valid
A well-formed document follows XML's syntax rules. A valid document also matches a schema (XSD) or DTD that says which elements are allowed, in what order, and with which types. This tool checks syntax only, so use your schema validator to check required fields or data types. JSON or YAML instead? Use the JSON formatter or YAML formatter.