XML Formatter

Paste or drop an XML document to indent it into readable, nested lines, or switch to minify mode to strip all whitespace between tags. Invalid XML is flagged immediately with a clear parser error, so you know exactly what to fix. Nothing is uploaded; formatting runs entirely on your device.

PrivateFreeWorks offline

Reviewed by Vincenzo Manto, Founder & Lead Developer · Last updated September 27, 2026

How it works

  1. 1

    Paste your XML or drop a .xml file into the input box.

  2. 2

    Choose Format to indent it, or Minify to strip whitespace between tags.

  3. 3

    Invalid XML is flagged instantly below the input with a parser error message.

  4. 4

    Copy the result or download it as a .xml file.

Readable XML for debugging and review

XML from APIs, config files, and data exports is often minified or inconsistently indented, making it hard to scan by eye. This formatter re-indents every open and close tag based on its nesting depth, turning a dense blob of markup into something you can actually read and review, whether you're debugging a SOAP response or checking a build configuration file.

A string-based approach, not a full DOM round-trip

Rather than relying on the browser's DOM serializer (which can silently reformat attributes or self-closing tags), this tool tokenizes the raw XML text and indents it directly, preserving your original tag and attribute formatting exactly except for the added whitespace. Validity checking still uses the browser's DOMParser, so you get accurate error messages without losing control over how well-formed XML gets re-indented.

Frequently asked questions

Does this tool upload my XML anywhere?

No. Formatting and validation run entirely in your browser, so the XML content is never sent to a server.

How does it detect invalid XML?

It parses your input with the browser's built-in DOMParser and surfaces the exact parser error (like a mismatched tag or invalid character) directly below the input box.

Does formatting preserve comments and CDATA sections?

Yes. Comments, CDATA blocks, and processing instructions like the XML declaration are kept intact and placed on their own indented line rather than being altered.

Can I choose the indentation size?

Yes, switch between 2-space and 4-space indentation using the selector above the input.

What does Minify mode do exactly?

It removes all whitespace-only text nodes between tags, collapsing the document to the smallest valid representation - useful before sending XML over the wire or embedding it in another file.

Related tools