XML Formatter

Runs entirely in your browser

Beautify and indent XML directly in your browser, based on element nesting.

Advertisement

Advertisement

What is XML Formatter?

XML Formatter re-indents an XML document so each nested element sits on its own line, making structure easy to scan. It's a text-based indenter, not a validator — it won't fix malformed XML, only make well-formed markup readable.

How to use XML Formatter

  1. Paste your XML into the Input box.
  2. Choose an indent size.
  3. Click Format, then copy the result.

Features

  • Indents nested elements based on tag structure.
  • Preserves CDATA sections and processing instructions exactly.
  • Correctly handles self-closing elements.
  • 100% client-side — your markup never leaves your browser.

Example

This compact XML:

<?xml version="1.0"?><root><item id="1"><name>Toolbeel</name></item></root>

becomes:

<?xml version="1.0"?>
<root>
  <item id="1">
    <name>
      Toolbeel
    </name>
  </item>
</root>

Tips for using XML Formatter

  • A processing instruction like <?xml version="1.0"?> is printed on its own line at the current depth but never changes the indentation depth itself — visible in the Example above, where it sits at the same level as <root>, not nested inside it.
  • Just like HTML Formatter, every text node — including a single word like "Toolbeel" — becomes its own indented line between its opening and closing tags.
  • Element and attribute names are matched with a pattern that allows letters, digits, underscores, hyphens, periods and colons, which covers namespaced tags like ns:tag commonly seen in RSS, Atom and SOAP documents.
  • This tool assumes your XML is already well-formed. It doesn't check tags against a DTD or XML Schema, and it won't catch a document with mismatched or unclosed elements — it will simply indent whatever structure it finds.

Is XML Formatter safe?

Yes. The tag-matching pattern described in the Tips above — which also handles namespaced elements and preserves CDATA sections and processing instructions exactly — runs locally in your browser, so the XML you paste is never sent to our servers.

Frequently Asked Questions

Are CDATA sections and processing instructions preserved?

Yes. <![CDATA[ ... ]]> sections and <?xml ... ?> processing instructions are kept exactly as written, on their own line.

Does this validate my XML?

No. This is a text-based indenter, not a validator — it won't catch mismatched tags or invalid XML, only reformat well-formed markup.

Are attribute values changed?

No. Attributes stay exactly as written on the same line as their tag — only element nesting is indented.

Related tools