CODDY Tool

XML Formatter

Indent, minify and validate XML — comments and CDATA survive untouched.

Turn dense or minified XML into readable, indented markup, or strip it back down for transport. Unlike a formatter that parses your document into an object and writes a new one, this re-indents the tokens you actually wrote, so comments and CDATA sections come through exactly as they were.

Everything you enter stays in this browser tab. Nothing is sent to our servers, logged or stored.

Loading tool…

What XML Formatter supports

Clean up

  • Format & indent
  • Minify
  • Validate

About XML Formatter

XML that has travelled through an API or a build step usually arrives on one line, which is efficient for a machine and unreadable for a person trying to see what a document actually contains. Formatting restores the structure.

The common way to build an XML formatter is to parse the document into an object and serialise a new one back out. That is simple, but it is lossy: comments disappear, because there is nowhere in a parsed object model to keep them, and so do processing instructions and the original attribute order. This formatter instead works directly on the document's own tags, moving only whitespace — so a comment left as a note for the next developer, or a CDATA block holding literal markup, survives exactly as written.

Validation is delegated to a dedicated XML parser rather than a hand-rolled check, since the well-formedness rules — matching tags, a single root element, correctly escaped entities — have edge cases a quick regex reliably gets wrong.

How to format XML

  1. Paste your XML

    Minified, hand-written, or exported from another tool.

  2. Choose an operation

    Format to indent it, minify to compact it, or validate to check it.

  3. Set the indent

    Two spaces, four spaces, or a tab.

  4. Copy or download

    Take the result to your clipboard or save it as a .xml file.

What survives formatting

  • Comments (<!-- ... -->) — kept in place, content untouched.
  • CDATA sections (<![CDATA[ ... ]]>) — kept as a single block, even when the content contains characters that look like tags.
  • Processing instructions (<?...?>), including the XML declaration.
  • Attribute order — never reordered, unlike a round trip through a parsed object.

Frequently asked questions

Does formatting change my data?

No. Only whitespace between tags is added or removed — every tag, attribute, comment and text node is preserved exactly. Minifying is the same operation in reverse.

Are comments kept?

Yes. This formats the document's actual tokens rather than round-tripping it through a parsed object, which is the approach most XML formatters use and the reason most of them silently drop comments.

Why did validation fail on XML that looks fine?

The most common causes are an unclosed tag, more than one root element, or an unescaped & or < inside text content — XML requires those to be written as &amp; and &lt; even though HTML is more forgiving about it.

Is my XML sent to a server?

No. Formatting, minifying and validation all happen in your browser, which matters because XML documents routinely carry configuration values, API keys or customer data.

All Developer Tools

XML Formatter is free to use with no account, no watermark and no usage limits. Last updated 3 September 2026.