devtools

XML Formatter

Format and beautify XML in your browser, or minify it to one line. Indent nested tags, keep comments and CDATA intact, and flag mismatched tags. No upload.

Runs entirely in your browser — your data never leaves your device.

How to use XML Formatter

What it does & when you need it

XML arrives in all shapes: a minified SOAP response on one line, a hand-edited pom.xml, an SVG exported without a single line break, an RSS feed you need to read. This tool re-indents that markup into a clean, nested tree so you can follow the structure — or, in reverse, collapses a tidy document down to the smallest single-line form for transport. It is a lightweight formatter written from scratch, so it runs instantly in your browser and never uploads what you paste.

How to use

  1. Paste your XML into the left buffer, or press Sample to load an example catalog with a declaration, comment, attributes, and a self-closing tag.
  2. Leave Minify off to pretty-print. Pick a 2 or 4 space indent from the dropdown.
  3. Tick Minify to strip the whitespace between tags and produce one compact line; the status bar reports how many bytes you saved.
  4. Press Copy result or Ctrl/Cmd + Enter to copy the output.

Things worth knowing

It preserves what matters. Attributes keep their exact quoting, the <?xml?> declaration stays on top, and comments, <![CDATA[ ]]> sections, and self-closing tags like <br/> pass through untouched. A > that appears inside a quoted attribute value will not fool the tokenizer into ending the tag early.

Short text stays inline. An element that wraps a single short text node, such as a title, is kept on one line as <title>XML Basics</title> rather than being exploded across three, which keeps the output compact and readable.

It catches broken nesting. The formatter tracks open tags on a stack, so a mismatched pair like <a></b> or an element you forgot to close reports an error that names the tag, instead of silently emitting garbage.

It is a formatter, not a schema validator. It will not check your document against a DTD or XSD, resolve entities, or confirm namespace prefixes are declared. For structured JSON instead, see the JSON formatter; for HTML markup, the HTML formatter understands void elements and inline whitespace rules that XML does not share.

Examples

Pretty-print a one-line document

<?xml version="1.0"?><catalog><book id="bk101"><title>XML Basics</title><price>39.95</price></book></catalog>

Re-indents the compact string into a nested tree, keeping the title inline as a short text element.

Comment, CDATA, and self-closing tag

<note><!-- draft --><body><![CDATA[x < y && y > z]]></body><hr/></note>

Shows that comments, CDATA (with its literal < and >), and the self-closing hr are preserved verbatim.

Catch a mismatched tag

<a><b>text</a></b>

The tags close in the wrong order, so the formatter reports a mismatch instead of emitting broken output.

Frequently asked questions

Does reformatting XML change what it means?

For element structure, no — pretty-printing only adds indentation and line breaks between tags, which are insignificant there. Be aware that whitespace inside an element that holds text can be significant, so a document relying on exact text spacing is best minified rather than re-indented.

Are comments, CDATA, and the XML declaration preserved?

Yes. The <?xml?> declaration is kept on the first line, and comments, <![CDATA[ ]]> sections, and self-closing tags like <br/> pass through untouched. Only the whitespace between tags is adjusted.

What does Minify do?

It removes the whitespace between tags and collapses the document onto a single line, which is useful for embedding XML in a string or shrinking a payload. The status bar shows the byte size before and after so you can see the saving.

Will a > inside an attribute value break the formatter?

No. The tokenizer tracks single and double quotes, so a greater-than sign inside an attribute such as href="a>b" is treated as part of the value and does not end the tag early.

Does it validate my XML against a schema?

No. It is a formatter, not a validating parser: it will not check a DTD or XSD, resolve entities, or confirm namespaces are declared. It does catch structural breakage — an unclosed or mismatched tag reports an error that names the tag.

Is my XML sent to a server?

No. Tokenizing, indenting, and minifying all run in your browser, so a SOAP response, config, or SVG you paste never leaves your machine and the tool works offline.