XML Formatter

Re-indent minified or messy XML into something readable, with text-only elements kept on one line.

215Input characters
13Output lines
9Tags
3Maximum nesting

Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.

What the XML Formatter does

Use this XML formatter to re-indent minified or messy XML into something readable, with text-only elements kept on one line. Paste your text in, pick the options you need, and copy the result straight back out. It is most often used for making a minified XML response readable while debugging. Companion tools to this one live on FreeToolStation.org.

How to use it

  1. Paste your XML.
  2. Choose the indentation you prefer.
  3. Read or copy the formatted result.
  4. Check the nesting depth figure if the structure is deeper than you expected.

How it works

This is a formatter, not a parser. It re-indents based on the tag structure it finds, which makes minified XML readable in a moment, but it does not validate: a document with mismatched tags will come out indented oddly rather than producing an error. If you need to know whether the XML is well formed, a validating parser is the right tool and this is not one.

Elements containing only text are kept on a single line, so a title or an author stays as `<title>Design Patterns</title>` rather than being exploded across three lines. That choice makes the output considerably more readable for the data-carrying XML most people deal with — a formatter that splits every element uniformly produces a document three times longer with no gain in clarity.

Whitespace in XML is significant in a way that catches people out. Between elements it is usually ignorable, which is what makes re-indenting safe for most documents. Inside an element it is part of the content, and a document using `xml:space="preserve"` means it everywhere. For a configuration file or a data feed, formatting is harmless; for a document where whitespace carries meaning, it is not.

The same formatter handles HTML reasonably, with one caveat: HTML permits unclosed tags such as `<li>` and `<p>` where XML does not, so the indentation of a document relying on those will drift. HTML-specific formatters track which elements may be left open; this one treats every opening tag as needing a close.

When to use it

  • Making a minified XML response readable while debugging.
  • Tidying a configuration file before editing it by hand.
  • Inspecting the structure of an RSS or sitemap file.
  • Preparing XML for a diff where indentation noise would obscure the changes.

Common mistakes to avoid

  • Expecting validation. Malformed XML is re-indented oddly rather than reported as an error.
  • Formatting a document where whitespace is significant, such as one using xml:space="preserve".
  • Using it on HTML that relies on unclosed tags, where the indentation will drift.

Frequently asked questions

Does this validate my XML?

No. It re-indents based on the tags it finds. Mismatched tags produce odd indentation rather than an error message. Use a validating parser if you need to know whether the document is well formed.

Why are some elements left on one line?

Elements containing only text are kept together on purpose — splitting `<title>Something</title>` across three lines makes the document longer and harder to read, not easier.

Will it work on HTML?

Mostly. The difference is that HTML allows tags such as <li> and <p> to be left unclosed, which XML does not, so a document relying on that will have drifting indentation.

Related tools

See all developer tools →