XML Formatter

Prettify and beautify messy XML documents with proper indentation for better readability and structure.

<root>
  <user id="1">
    <name>John Doe
    </name>
    <email>john@example.com
    </email>
    <roles>
      <role>admin
      </role>
      <role>editor
      </role>
      </roles>
      </user>
      </root>

Custom Indentation

Automatically applies consistent 2-space indentation to your XML tags, making complex hierarchies easy to traverse at a glance.

Data Cleaning

Cleans up extra whitespace between tags while preserving the integrity of your data values and attributes.

About the XML Formatter

Paste raw or single-line XML and get it indented with one element per line, so the structure of feeds, SOAP messages and config files is easy to follow.

Everything you enter is processed in your browser; nothing is uploaded or stored.

How to use it

  1. Paste your XML into Raw XML.
  2. Choose the indentation if offered.
  3. Copy the result from Beautified XML.

How the XML formatter indents

The formatter splits the document at each tag, then writes every element on its own line, indenting one level for each opening tag and stepping back for each closing tag. Self-closing tags and text nodes keep their place.

Formatting never changes the data – element names, attributes and text stay identical – so the output can replace the original file.

Example

<users><user role="admin"><name>John Doe</name></user></users> becomes a nested tree with <user> indented under <users> and <name> under <user>.

Tips

  • Whitespace inside text nodes can matter in some XML formats (for example mixed content); check those after formatting.
  • To turn XML into JSON for a JavaScript app, use the XML to JSON converter.

Frequently asked questions

Does the formatter validate XML?

It focuses on indentation. Badly nested tags will show up as broken indentation, which helps you find them.

Can I format large XML files?

Yes, within what your browser can hold in memory; the file is not uploaded.

What is the difference between XML and HTML?

XML is a strict, general data format where you define the tags; HTML is a fixed vocabulary for web pages.