XML Formatter

Beautify minified or one-line XML — each element on its own line, indented by nesting level — right in your browser. A quick regex tidier, not a validating parser.

Developer Tools Free No upload Instant

Loading XML Formatter…

Your browser is preparing the tool. It runs 100% locally.

Quick Answer

Paste compact or one-line XML and the tool reformats it so each element sits on its own line, indented two spaces per nesting level, with text on its own line too. It is a lightweight regex tidier — it does not parse or validate the XML — so it is ideal for a quick read but can stumble on attribute values or CDATA that contain angle brackets. It runs in your browser; nothing is uploaded.

What the XML Formatter Does

This tool takes XML that has been collapsed onto one line and lays it out with one tag per line and a clean two-space indent for each level of nesting, so the document structure is easy to follow.

It is the quick way to read an API response, a config file or a feed that arrived minified — to see the hierarchy of elements without loading it into an editor or an XML viewer.

How It Works

The tool first removes whitespace between tags, then splits the text into its tags and text nodes. It walks through those pieces keeping a nesting depth: an opening tag increases it, a closing tag decreases it, and each piece is indented two spaces per level. Declarations, comments and self-closing tags are recognised so they do not wrongly change the depth.

This is pattern-based, not a parse. The tool never builds a document tree or checks that the XML is well formed — it reacts to the shape of the tags. That keeps it fast and dependency-free, and it handles ordinary documents well, while the edge cases a real parser handles can trip it up.

Processing pipeline

  1. Collapse and split. Remove whitespace between tags, then split the text into tags and text nodes.
  2. Track nesting depth. Raise the depth on an opening tag and lower it on a closing tag, ignoring declarations and self-closing tags.
  3. Indent each piece. Indent every tag and text node two spaces per level of depth.
  4. Join the lines. Reassemble the indented pieces into the formatted XML, ready to copy.

How it reformats

1 · collapse whitespace between tags, then split into tags and text 2 · opening tag → indent deeper · closing tag → step back out 3 · two spaces of indent per nesting level note: declarations, comments and self-closing tags do not change the depth
Worked example
Before: <note><to>Tove</to><from>Jani</from></note> After: <note> <to> Tove </to> <from> Jani </from> </note>

Text nodes go on their own indented line, so an element's text sits one level deeper than its tags. Self-closing and declaration tags are detected so they do not push the indentation.

Privacy

Your XML never leaves your device. It is reformatted in your browser with no network request, so nothing is uploaded.

Because the work is local, you can safely tidy private API responses, configs or client data without it being stored or sent anywhere.

Nothing persists between sessions — close the tab and the input and output are gone.

Standards & references

  • XML 1.0 — The W3C standard for well-formed markup: properly nested elements, quoted attributes, a single root, and matching tags. The tool relies on the angle-bracket shape of tags, not a formal check of well-formedness.
  • Declarations and CDATA — An XML prolog, comments and CDATA sections can contain characters that look like tags. The tool detects the common declaration and comment forms but does not fully parse CDATA, so angle brackets inside it can confuse the split.
  • Parser-based formatters — Tools built on a real XML parser (such as a DOM parser or xmllint) validate well-formedness and reprint from a tree, giving reliable, idempotent output. This tool is a lighter regex tidier.

Accuracy & Limitations

It lays out ordinary, well-formed XML cleanly, but it is a regex tidier, not a parser. It does not check that the document is well formed or that tags match — it only reflows the pieces, so malformed input produces malformed output.

An angle-bracket character inside an attribute value or a CDATA section can break the tag splitting, because the tool keys off those characters rather than understanding quoting and CDATA. A real parser tracks both.

Text nodes are placed on their own indented line, so an element's text appears one level deeper than its surrounding tags. That is readable but differs from formatters that keep short text on the same line as its element.

It does not handle XML-specific niceties like namespace alignment or attribute reordering, and it is not guaranteed idempotent on already-formatted input. For anything beyond a quick read, a parser-based tool is safer.

Real-World Use Cases

Reading an API response

Expand a minified XML payload into a readable hierarchy.

Inspecting a config

Lay out an XML configuration file to see its structure.

Reviewing a feed

Format an RSS or sitemap document for a quick scan.

Teaching and notes

Present XML clearly in documentation.

When to use it — and when not to

Good for

  • Reading minified or one-line XML
  • Seeing the element hierarchy
  • Tidying a payload for review
  • A fast, no-install format

Not the best choice for

  • Validating well-formedness
  • Documents with CDATA or angle brackets in attributes
  • Namespace-aware or canonical formatting
  • A guaranteed idempotent reformat

For a reliable reformat that also checks well-formedness, use a parser-based tool (a DOM parser, xmllint, or your editor's XML plugin). This tool is for a fast in-browser read of a payload.

Frequently Asked Questions

Does it validate or check well-formedness?
No. It only reflows and indents the markup. It does not confirm the XML is well formed or that tags match, so broken input comes out broken. For validation, use a parser-based XML tool.
Why did an attribute with an angle bracket break the layout?
The tool splits on the angle-bracket characters that delimit tags. An angle bracket inside a quoted attribute value looks like the end of a tag to it, so the split goes wrong. A real parser understands quoting and avoids this.
Is it a real XML parser?
No. It uses regular expressions to split tags and text and to count nesting depth. It never builds a document tree, which is why it is fast but can be fooled by edge cases.
Why is the text indented deeper than its tags?
Text nodes are placed on their own line at the current depth, so an element's text ends up one level deeper than its opening and closing tags. It is readable, just more spread out than some formatters.
Does it handle CDATA sections?
Only loosely. It detects common declaration and comment forms, but it does not fully parse CDATA, so angle brackets inside a CDATA block can confuse the split. A parser handles CDATA correctly.
Does it support self-closing tags?
Yes. A self-closing tag is detected so it does not increase the nesting depth — it stays on its own line without indenting what follows.
Is my XML uploaded anywhere?
No. It is formatted entirely in your browser. Nothing is sent to a server, so private payloads stay on your device.
How much indentation does it use?
Two spaces per nesting level, applied to every tag and text node according to its depth in the document.
Can it format a whole large document?
You can paste it in, but for large files or anything with CDATA, namespaces or attribute edge cases, a parser-based tool is more reliable.
Will it preserve my XML declaration and comments?
Yes. The prolog and comments are kept and detected so they do not wrongly change the indentation, though complex comment content is not fully parsed.
Why did a second run change the output?
It is not guaranteed idempotent, because it reacts to the current spacing rather than rebuilding from a parsed tree. A parser-based formatter gives the same result every time.
Should I use this or a parser-based tool?
For a quick in-browser read of a payload, this is handy. For validation, large documents or anything with CDATA and namespaces, a parser-based XML formatter is the better choice.

References

Re-indents with a regex that splits on tags and counts nesting depth; honest that it does not parse or validate the XML, so attribute values and CDATA with angle brackets can throw it off.

PopularHot

JSON Formatter

JSON Formatter for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

JSON Validator

JSON Validator for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Base64 Encoder

Base64 Encoder for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Hash Generator

Fast, free Hash Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Popular

UUID Generator

Fast, free UUID Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Trending

CSS Minifier

Fast, free CSS Minifier that runs entirely client-side in your browser.

DeveloperOpen Tool

Ready to try the XML Formatter?

It is free, private and runs entirely in your browser — no sign-up, no uploads, no limits.