XML Formatter
Re-indent XML so its structure is readable, and find out immediately if it is not well-formed. CDATA sections and declarations are preserved exactly.
Your data never leaves your browser. This tool runs entirely on your device.
Well-formed versus valid
These are two different checks and the distinction matters. Well-formed means the syntax is correct: every element is closed, tags nest properly, attribute values are quoted, and there is exactly one root element.
Valid means the document also conforms to a schema — a DTD, XSD or RelaxNG — that defines which elements may appear where. This tool checks well-formedness, which is the prerequisite for everything else.
How XML differs from HTML
XML is far stricter. Every element must be explicitly closed, tag names are case-sensitive, and attribute values must always be quoted. HTML forgives all three.
That strictness is why an XML formatter can safely reject input, while an HTML formatter has to accept whatever it is given.
CDATA and declarations
A CDATA section marks text that must not be parsed as markup, which is how XML carries embedded code or content containing angle brackets. It is copied through byte for byte.
The XML declaration and any processing instructions are kept on their own lines at the top of the document.
Frequently asked questions
What does "not well-formed" mean?
The document breaks a basic syntax rule of XML — usually an unclosed tag, tags that overlap instead of nesting, an unquoted attribute value, or more than one root element. Any XML parser will reject it.
Does this validate against a schema?
No. It checks well-formedness only. Validating against an XSD or DTD requires the schema itself and a validating parser, which is a separate step.
Why can an XML file have only one root element?
Because the specification defines a document as a single element tree. Two sibling elements at the top level have no common parent, so there is no tree — wrap them in a container element.
Is HTML valid XML?
Usually not. HTML permits unclosed tags like <br> and <li>, and unquoted attributes, all of which XML forbids. XHTML was the strict variant designed to be both; use the HTML formatter for ordinary HTML.
Related tools
- HTML FormatterRe-indent HTML so its nesting is readable. Fragments work as well as whole documents, and the contents of pre, script and style blocks are left exactly as written.
- JSON FormatterPaste JSON to pretty-print it with consistent indentation, or minify it back down. Invalid JSON is reported with the exact line and column so you can find the problem.
- YAML to JSONConvert YAML into JSON. Parse errors are reported with a line and column so you can find the problem, which in YAML is usually indentation.
- CSS FormatterRe-indent CSS so it is readable, or minify it for production. Nested at-rules, comments and quoted values are all handled correctly.