XML Formatter and Beautifier
Re-indents XML so its structure is readable, keeping text-only elements on one line so no whitespace enters a value.
Loading the tool…
How to use this tool
- Paste your XML into the input box, or load an .xml file from your machine.
- Choose the indentation, and decide whether to keep the declaration and any comments.
- Select Format. If the document is not well-formed the error names the line and column.
- Copy the result, or download it as a file.
What xml formatter does
Formatting XML is less innocent than formatting JSON. In JSON, whitespace between tokens carries no meaning and reformatting is always safe. In XML, the whitespace inside an element is text, and a parser hands it to the application unless the schema or the reader has been told otherwise. Breaking <name>Ada</name> across three lines changes that element from the string "Ada" to a string with a newline and two spaces on either side of it.
This formatter therefore indents structure but never text. An element whose children are all text stays on a single line, exactly as it was, and only elements that contain other elements get broken and indented. Attributes stay on the opening tag, comments are kept in place, and CDATA sections are passed through byte for byte.