Developer tools · free · no signup

XML Formatter

Indent XML and catch mismatched or malformed markup. Your work stays on this device whenever possible.

Free to useNo accountClear results
Preparing tool…
Simple, transparent workflow

How to use XML Formatter

  1. Paste your markup into the XML input box.
  2. Open 'Indentation' and pick '2 spaces', '4 spaces', 'Tabs' or 'Minify (collapse whitespace)'.
  3. Tick 'Sort element attributes alphabetically' if you want attributes reordered.
  4. Press 'Format XML' and check the notice for element count and size.
  5. Use 'Download XML' to save the tidy version as formatted.xml.

Worked example

Paste <catalog><book id="1"><title>Dune</title><price>9.99</price></book></catalog> with '2 spaces'. The output is <catalog>, then <book id="1"> indented by two, then <title>Dune indented by four with </title> on the next line at the same depth, likewise for price, then </book> and </catalog> dedented. The notice counts 4 elements.

When to use this tool

  • Reading a one-line SOAP or feed response from a log file.
  • Alphabetizing attributes so two config files diff cleanly.

Important limitations

Requires strict well-formed XML syntax. Unclosed tags, unquoted attributes, or mismatched tags stop formatting with specific line indicators. Does not validate against external DTD or XSD schemas.

Frequently asked questions

Does it validate against a schema?

No. It only checks that the XML is well formed using the browser's parser and shows the first line of the parser error if not. DTD and XSD validation are not included.

How does it format text elements?

The text stays attached to the opening tag while the closing tag drops to the next line, so <title>Dune</title> becomes two lines. Read mixed content carefully.

Will HTML work?

Only if it is well formed. The strict XML parser rejects unclosed tags such as <br> and unquoted attributes, so paste XHTML, or repair the markup first, before expecting a formatted result.

Does the self-closing option matter?

Rarely. The browser's serializer already writes empty elements as <tag/>, so ticking or clearing the option changes little in practice. It remains as a safeguard for any empty pair that survives.

What about the XML declaration and comments?

The document is re-serialized by the browser, so check that your <?xml ...?> line and any processing instructions are still there. Comments and CDATA sections are kept.

What does 'Minify (collapse whitespace)' remove?

It deletes whitespace that sits between a closing bracket and the next opening bracket, then returns one continuous line. Text inside an element is untouched, and the element and size counters below the box are not shown for this mode.