XML formatter

Prettify your XML string into a friendly, human-readable format.

Enable JavaScript to use the interactive tool. The guide below explains how it works.

XML Formatter

What it does

The XML Formatter takes minified or messy XML and rewrites it with consistent line breaks and indentation, so the hierarchy of elements is easy to read. It also tells you whether your XML is well-formed. You can choose the indent size (0–10 spaces) and whether short text content should stay on the same line as its tag.

Why someone uses it

Step-by-step instructions

  1. Paste XML into the input. A short example is pre-filled.
  2. Set Indent size.
  3. Choose whether to Collapse content, which keeps <a>text</a> on one line.
  4. Copy the formatted result from the output.

Examples

Input: <hello><world>foo</world><world>bar</world></hello>

Output with 2-space indent:

<hello>
  <world>foo</world>
  <world>bar</world>
</hello>

Understanding the results

Each nested element is indented one level deeper than its parent, so you can read the tree from left to right. With Collapse content on, elements containing only text stay on one line; with it off, the text sits on its own indented line. Formatting changes only whitespace between elements, not element names, attributes or text values. If the input is not well-formed (an unclosed tag, mismatched names, unescaped & or <), the tool shows "Provided XML is not valid." instead of output.

FAQs

Common mistakes

Use cases

Related tools

All tools

Guides and articles