XML Formatter
Format or minify XML with 2 spaces, 4 spaces or tabs. Comments, CDATA, DOCTYPE, attribute values and mixed content stay as written, up to 300,000 characters. How it works
Use the XML Formatter
Up to 300,000 characters (files up to 2 MB). Only the spaces, tabs and line breaks between elements change (any other character, such as a no-break space, is text and stays).
Output
What changes and what does not
Comments, processing instructions (also after the root), the whole DOCTYPE, CDATA sections, entity references, attribute values and text are copied as written. Mixed content (text next to child elements), text-only elements and anything under xml:space="preserve" are never re-flowed or trimmed, because their spaces are data.
The tool checks well-formedness with the browser's XML parser. It does not validate against a DTD or schema. The XML declaration is kept as written; the text you copy is Unicode whatever its encoding= says.
About the XML Formatter
Format puts each child of an element-only element on its own line, indented by 2 spaces, 4 spaces or a tab, so <a><b>1</b><c/></a> becomes four lines; Minify removes that white space again. Only the spaces, tabs and line breaks between elements change: comments, CDATA, the DOCTYPE, attribute values, mixed content and anything under xml:space="preserve" are copied as written.
What Format and Minify do
| Input | Format (2 spaces) | Minify |
|---|---|---|
| <a><b>1</b><c/></a> | <a> ⏎ <b>1</b> ⏎ <c/> ⏎ </a> | <a><b>1</b><c/></a> |
| <p>Hello <b>world</b> again</p> | <p>Hello <b>world</b> again</p> | <p>Hello <b>world</b> again</p> |
| <a xml:space="preserve"> <b> x </b> </a> | <a xml:space="preserve"> <b> x </b> </a> | <a xml:space="preserve"> <b> x </b> </a> |
| <a><!-- note --><![CDATA[ <raw> ]]></a> | <a><!-- note --><![CDATA[ <raw> ]]></a> | <a><!-- note --><![CDATA[ <raw> ]]></a> |
| <a x="1" y='2' ><b /></a> | <a x="1" y='2'> ⏎ <b/> ⏎ </a> | <a x="1" y='2'><b/></a> |
| <a><b> padded </b></a> | <a> ⏎ <b> padded </b> ⏎ </a> | <a><b> padded </b></a> |
⏎ marks a line break in the output. Mixed content (text next to a child element), xml:space="preserve" and an element holding a comment next to CDATA are copied on one line as written; text inside an element is never trimmed.
Limits
| What | Limit |
|---|---|
| Input | 300,000 characters (files up to 2 MB) |
| Nesting for Format, Minify and the tree | 1,000 levels |
| Highlighted output | 50,000 characters; longer output is shown as plain text |
| Tree view | 20,000 nodes, 100 children of a branch at a time |
Common well-formedness errors and the message in Chrome
| Input | What is wrong | Message shown |
|---|---|---|
| <a><b>1</c></a> | The closing tag does not match the open element | Invalid XML at line 1, column 12: Opening and ending tag mismatch: b line 1 and c |
| <a><b>1</b> | An element is never closed | Invalid XML at line 1, column 12: Premature end of data in tag a line 1 |
| <a x=1/> | An attribute value without quotes | Invalid XML at line 1, column 6: AttValue: " or ' expected |
| <a>Fish & chips</a> | A bare & in text; write & | Invalid XML at line 1, column 10: xmlParseEntityRef: no name |
| <a>1 < 2</a> | A bare < in text; write < | Invalid XML at line 1, column 7: StartTag: invalid element name |
| <a/><b/> | Two root elements | Invalid XML at line 1, column 5: Extra content at the end of the document |
| <a> </a> | An HTML entity that XML does not define; write   | Invalid XML at line 1, column 10: Entity 'nbsp' not defined |
Messages as the page showed them in Chrome 152 on Linux on 22 October 2026. The text after the position comes from the browser’s XML parser, so Firefox and Safari word it differently and can point at another column.
Frequently asked questions
- How do I pretty print XML?
- Paste the XML or press Load File, choose 2 spaces, 4 spaces or Tabs, and press Format. Copy takes the result, and Download .xml saves it as formatted.xml, or minified.xml after Minify. The output belongs to the text it was made from: after an edit or a new indent the page asks you to press Format again. The Tree view shows the same result as collapsible elements with a search box.
- Does the XML formatter change my text or attribute values?
- No. Attribute values keep their quotes and characters, so y='2' stays in single quotes, and text is never trimmed: <b> padded </b> keeps both pairs of spaces. What changes is the white space between elements and inside a tag: <a x="1" y='2' ><b /></a> minifies to <a x="1" y='2'><b/></a>. A no-break space is text, not white space, so it stays.
- Why is part of my XML not indented?
- An element that mixes text and child elements, such as <p>Hello <b>world</b> again</p>, is copied on one line, because adding line breaks there would change the text. The same goes for anything under xml:space="preserve" and for elements that hold only text.
- Does it validate XML against a DTD or schema?
- No. It checks that the document is well-formed with the browser's own XML parser and shows the reason with the line and column, for example a closing tag that does not match, half a second after you stop typing. It does not validate against a DTD or an XSD, and it does not expand entities.
- How large an XML file can it format?
- Up to 300,000 characters; the Limits table above lists the file size, nesting, highlighting and tree limits. For a larger file, such as a full database export, the page suggests a command-line tool: xmllint --format file.xml prints the same kind of indented output.
- Is my XML saved or uploaded?
- A loaded file is read in your browser and is not uploaded. The input, the indent and the view are saved in this browser's local storage a moment after you stop typing, until you press Clear Saved Values.
Related Tools
View all toolsCSS Minifier
Paste CSS to remove comments and unneeded whitespace while keeping descendant spaces, calc() operators and /*! */ license comments, with the characters saved.
JS Minifier
Paste JavaScript to remove comments and unneeded whitespace. Line breaks the code relies on and /*! license comments stay; variable names are not shortened.
HTML Minifier
Paste HTML to drop comments and collapse whitespace. The space between inline elements stays, pre and textarea are kept, and inline CSS and JS can be minified.
SQL Query Formatter
Format SQL for Standard SQL, PostgreSQL, MySQL, SQLite or SQL Server, with keywords kept, upper-cased or lower-cased and 2-space, 4-space or tab indents.
JSON Formatter
Paste JSON to format it with 2 spaces, 4 spaces or tabs, minify it or sort its keys. A syntax error is reported with its line, column and a caret under it.
CSV to XML
Convert CSV to XML: each row becomes a row element with one child per column, headers become valid XML names, and quoted commas and line breaks are kept.