Small Tools
YAML, XML & Data utility

XML Formatter

Format XML with readable indentation and validate its structure.

● This tool runs entirely in your browser. Your input is never uploaded to our servers.
Output
Your result will appear here…

How to use XML Formatter

  1. Paste your XML.
  2. Select Format.
  3. Copy the indented result.

Example

Input / settings:

<catalog><item id="1"><name>Notebook</name></item></catalog>

Output:

<catalog>
  <item id="1">
    <name>Notebook</name>
  </item>
</catalog>

Formatting the output again returns the same text.

When to use

Overview

XML Formatter parses your document with the browser's XML parser and writes it back with each element on its own line, indented by two spaces. It keeps comments, processing instructions, CDATA sections and the XML declaration, and it reports an error for malformed XML. It does not preserve whitespace inside text, and it leaves out the DOCTYPE.

Supported input

XML text

Output details

formatted XML

Limitations

Common mistakes

Practical tips

Privacy and security

This tool runs entirely in your browser. Your input is never uploaded to our servers. The XML is formatted in your browser and is never uploaded. The tool re-serializes the parsed document, so treat its output as a copy of the data, not as a byte-for-byte equivalent of the input.

References

Frequently asked questions

Does XML Formatter keep CDATA sections and comments?

Yes. Comments, processing instructions and CDATA sections are written back in document order.

Does the XML declaration survive formatting?

Yes. A declaration at the start of the input is copied exactly, including single quotes, as the first line.

Are attributes reordered or requoted?

Attributes keep their order, and values are written with double quotes.

Related tools