XML Formatter
Check that XML is well-formed, then indent it
About XML Formatter
XML Formatter first checks your XML with the validator of fast-xml-parser. If a tag is unclosed or mismatched, it shows Invalid XML with the line and column and produces nothing. Valid XML is then re-indented by 2 spaces per level: a line break is added only between a closing > and the next <, never inside CDATA sections, comments, or quoted attribute values, and the XML declaration does not shift the indentation. It does not check a DTD or XSD schema, and the indentation cannot be changed. Validation and indentation both happen in your browser.
Example
A one-line catalog with a declaration and a self-closing tag.
Input
<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><tags/></book></catalog>
Output
<?xml version="1.0"?>
<catalog>
<book id="b1">
<title>XML Basics</title>
<tags/>
</book>
</catalog>How to format and validate XML
- 1Paste XML into "Input".
- 2Click "Format".
- 3If a red Invalid XML line appears, fix the tag at the line and column it gives and click "Format" again.
- 4Click "Copy", or "Download" to save "formatted.xml".
Formats and limits
- Input
- XML text; the XML declaration and a DOCTYPE are accepted
- Output
- XML indented by 2 spaces per level, saved as formatted.xml
- Check
- Well-formedness only (tags, nesting, characters); several root elements pass; no DTD or XSD validation
- Known limits
- A start tag written over several lines, or an attribute value containing >, shifts the indentation of what follows; lines inside a multi-line CDATA section or comment are re-indented
Where your XML is processed
Validation and indentation both run in this page: fast-xml-parser is downloaded on your first click on "Format" and reads the XML on your device, which is not uploaded. An Invalid XML or Error formatting XML message shown on screen is reported to our error log, with quoted tag names, long numbers, and addresses removed, plus the tool name and your browser's name and version.
Frequently asked questions
Does it check whether my XML is well-formed?
Yes. Before formatting, the validator looks for unclosed or crossed tags, bad attribute syntax, and text before the root element (text after it passes), and reports the first problem with its line and column. It does not compare the XML with a DTD or an XSD schema.
Can I change the indentation?
No. Each nesting level is indented by 2 spaces and there is no setting to change it. Elements that hold only text, such as a title, stay on one line with their closing tag.
Are CDATA sections and comments kept?
Yes, their content is never split and no line break is added inside them. One change remains: when a CDATA section or comment spans several lines, each of those lines loses its leading spaces and takes the current indentation.
Can a multi-line start tag break the indentation?
Yes. When a start tag spans several lines, or one of its attribute values contains a > character, the formatter misses the opening level but still counts the closing tag. Put the tag on one line, or write > as >, and format again.