Skip to content

XML Formatter

Beautify and indent XML.

Input
Output

No result

About XML Formatter

The XML formatter puts each element on its own line and indents children beneath their parent, turning a document that arrived as one continuous line into something whose hierarchy can be read at a glance. Escaping and attribute quoting are handled by the parser, so the output remains a valid document rather than a cosmetic rearrangement.

The reason single-line XML is so common is that it is what serialisers emit by default — whitespace between elements is insignificant to a parser, so there is no incentive to produce it, and it saves bytes. That is fine for machines and close to unreadable for anyone trying to work out why an element is not where they expected.

Formatting is non-destructive. Since whitespace between elements carries no meaning in XML, the reformatted document is parsed identically to the original by any conforming processor — it is purely a matter of how it reads to a person.

How to use XML Formatter

  1. 1 Paste the XML document.
  2. 2 Each element is placed on its own line and indented by depth, updating as you type.
  3. 3 Copy the output for use in documentation, code review, or debugging.

Frequently asked questions

Will reformatting break my document?

No. Whitespace between elements is not significant in XML, so a conforming parser reads the reformatted version identically to the original. Only whitespace that forms part of an element's text content is meaningful, and that is preserved.

What happens if the XML is malformed?

The parser reports the problem instead of formatting it. Formatting a document that does not parse would produce something that looks like valid XML while actually being broken, which is the worst possible outcome when you are diagnosing a failure.

Does it reorder or clean up anything?

No. Element order, attributes and content are preserved exactly as written. The only change is the addition of line breaks and indentation between elements.

Can I go back to a single line afterwards?

Yes — the XML Minify tool removes the inter-element whitespace again. Nothing is lost in either direction, so you can format for reading and minify for transfer freely.

Free, online, and private

Free to use

XML Formatter is completely free. There is no account to create, no login, and no hidden charge or usage limit.

Runs online in your browser

It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.

Your data stays private

All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.

How XML Formatter behaves in detail

These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.

Parameter Value
Parser DOMParser with the text/xml mime type — a real XML parser, not a regex pass
Reformatting step a newline is inserted wherever a `>` is immediately followed by `<`
Indent none — no space or tab is added at any depth
Parse errors no parsererror check, so a malformed document is serialized as the parser's error document rather than a message
Normalisation attribute quoting, empty-element style and entity escaping come from the serializer, not the input

Compiled from the implementation of this tool and checked against it by itoolnet.

What XML Formatter does not do

Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.

  • Nothing is indented. Every element begins at column zero, so the nesting depth of the result is visible only by reading tag names, not by following the layout.
  • Only directly adjacent tags are split. If the source already holds a space or a text node between "</a>" and "<b>", nothing is inserted and the existing whitespace is neither reformatted nor removed.
  • There is no error path at all. Unlike XML to JSON, which inspects the parse result for a parsererror node and throws, this tool serializes whatever came back, so broken XML is echoed as an error document instead of a readable problem.
  • It never normalises whitespace inside the document — a stray double newline pasted in from a terminal stays in the output, and so does indentation carried over from the source.

Tested and documented by itoolnet, the team that builds and maintains this site.

Share & embed this tool

Writing a guide or article? You are welcome to link to XML Formatter with the snippet below. It is free, runs entirely in your browser, and needs no signup.