Beautify XML
Format and pretty-print XML with configurable indentation. Transforms compressed or poorly formatted XML into clean, human-readable output.
What is XML Beautification?
XML beautification (also called pretty-printing or formatting) is the process of re-serialising an XML document with consistent indentation, line breaks, and whitespace to make its hierarchical structure immediately readable. The document's data content is unchanged - only insignificant whitespace between elements is added.
Minified or machine-generated XML often arrives as a single continuous line with no whitespace at all. Beautifying it lets you inspect element nesting, spot missing closing tags, and understand the document tree without a dedicated XML editor.
How the Formatter Works
The formatter parses your input using the browser's native DOMParser API,
which validates well-formedness before a single character of output is written. It then
walks the resulting DOM tree recursively, applying the following rules:
- Processing instructions (
<?xml ... ?>) are emitted at depth 0 with no indentation. - Each element is opened on its own line, indented by its nesting depth times the chosen indent unit.
- Elements with a single text-node child are collapsed onto one line:
<title>Value</title>. - Empty elements are self-closed:
<br/>. - Attribute values and text content are re-escaped to ensure valid XML output.
- With "Strip Comments" enabled, comment nodes are dropped from the output tree before serialisation.
Indentation Options
2 Spaces
The most compact readable option. Preferred in web-facing XML, JSON-adjacent configs, and projects following Prettier or ESLint defaults.
4 Spaces
The traditional choice for XML in Java, .NET, and enterprise tooling. Maven pom.xml, Spring configs, and WSDL files conventionally use 4-space indentation.
Tabs
Tab indentation lets each developer set their own visual width. Common in projects using .editorconfig rules that mandate tabs, including the Linux kernel's XML documentation.
Common Use Cases
API Response Inspection
SOAP services and legacy REST APIs often return XML in a single unreadable line. Paste the raw response here to understand the schema before writing a parser.
Config File Cleanup
Maven pom.xml, Android AndroidManifest.xml, and Spring XML configs can drift in indentation after merges. Reformat them to restore consistency.
SVG & HTML Debugging
SVG exported from Figma or Illustrator is typically a dense single line. Beautify it to locate specific path elements, clean up inline styles, or manually optimise the markup.
Diff Preparation
Formatting two XML files with the same indent settings before running a diff removes whitespace noise from the output, making structural changes the only visible differences.
Whitespace in XML: Significant vs. Insignificant
The XML specification distinguishes between significant whitespace (whitespace inside mixed-content elements that is part of the document's data) and insignificant whitespace (indentation whitespace between element-only content). Beautifiers only add insignificant whitespace.
If your document uses xml:space="preserve" on an element, the
whitespace inside that subtree is considered significant and must not be altered. This
formatter respects that contract by leaving text-node content untouched while only
introducing whitespace between sibling element nodes.