Skip to content
TinySolve

XML Formatter

Indent XML properly, and be told when a tag is closed in the wrong place.

Runs in your browser — nothing you type is sent anywhere

Indentation

Formatted

The result appears here as you type. Nothing is sent anywhere — the work happens in this page.

Comments and CDATA sections are passed through untouched, since their contents are not markup. Tag names are checked as it goes, so a tag closed in the wrong order is reported rather than silently indented.

About the XML Formatter

XML that arrives from an API, a configuration file or an export is usually either one long line or indented by nothing in particular. Reindenting it by depth makes the structure visible, which is the only reason anyone opens an XML document by hand.

It also checks as it goes. Tag names are tracked on the way in, so a tag closed in the wrong order — <code>&lt;a&gt;&lt;b&gt;&lt;/a&gt;&lt;/b&gt;</code> — is reported by name rather than indented happily into output that no parser will accept. That is the difference between a formatter that counts depth and one that understands the document.

Comments and CDATA sections are passed through exactly as written. The contents of a CDATA block are not markup, so reformatting them would change their meaning; several formatters get this wrong and quietly corrupt embedded scripts and SQL.

Short text content stays on the same line as its tags, so <code>&lt;name&gt;Ada&lt;/name&gt;</code> remains one readable line rather than becoming three. An element whose text is split across lines reads worse than the input did, which defeats the purpose.

There is no dependency behind this — it is a small amount of code that runs in your browser. Nothing is uploaded, which matters for the configuration files and API responses that make up most XML people need to read.

How to use the XML Formatter

  1. Paste your XML

    A document, a fragment or an API response. A declaration at the top is fine.

  2. Choose the indentation

    Two spaces, four spaces or tabs.

  3. Format it

    If a tag is closed in the wrong order, you are told which one rather than getting invalid output.

  4. Copy or download

    Take it to the clipboard or save it as an .xml file.

Frequently asked questions

Does it check the XML as well as format it?
It checks the structure: tag names are tracked, so a tag closed in the wrong order or never closed at all is reported by name. It does not validate against a DTD or schema, which is a separate job.
What happens to CDATA?
It passes through untouched. The contents of a CDATA block are not markup, so reindenting them would change their meaning — which is how some formatters quietly corrupt embedded scripts and SQL.
Why is short text kept on one line?
Because splitting <name>Ada</name> across three lines makes it harder to read, not easier. Text stays with its tags; only elements containing other elements are broken out.
Does it work for HTML?
Not reliably. HTML allows unclosed tags like <br> and <img>, which are errors in XML. Use the HTML formatter for HTML — it understands those rules.
Is my XML uploaded?
No. The formatting happens in your browser. Most XML people need to read is a configuration file or an API response, so that matters.