Skip to content
ToolZone

XML Formatter

Beautify compact or poorly indented XML into a readable, properly nested structure, or minify it down to remove unnecessary whitespace.

Runs in your browser. Nothing you enter or upload leaves your device.

Output…

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the XML Formatter

The XML Formatter takes raw or minified XML and returns it either neatly indented or compressed. It parses the document first, so malformed XML is flagged rather than formatted incorrectly.

How it works

The input is parsed with the browser's DOMParser as XML. If the parser reports an error, the output shows "Error: Invalid XML". Otherwise the root element is serialized back to text, which normalizes the markup.

In Beautify mode a line break is inserted between every pair of adjacent tags, and each line is indented by two spaces per nesting level. In Minify mode any whitespace between a closing > and the next < is removed. Because only the root element is serialized, an XML declaration such as <?xml version="1.0"?> and comments outside the root are not included in the output.

How to use

  1. 1

    Choose Beautify or Minify.

  2. 2

    Paste your XML into the input box.

  3. 3

    Read the result in the output panel.

  4. 4

    Click Copy to copy the formatted XML.

Worked examples

Beautify

A one-line catalog.

Input
<catalog><book id="1"><title>XML Basics</title><price>29.99</price></book></catalog>
Result
<catalog> <book id="1"> <title>XML Basics</title> <price>29.99</price> </book> </catalog>

Minify

Indented XML to a single line.

Input
<note> <to>Ana</to> <from>Ben</from> </note>
Result
<note><to>Ana</to><from>Ben</from></note>
Limitations
The XML declaration and comments or processing instructions outside the root element are dropped. Elements with single-letter names (such as <a> or <p>) are not indented as parents, so nesting under them can come out misaligned. Invalid XML produces a generic error without details.
Assumptions
Input is a single well-formed XML document.
Privacy
Parsing and formatting happen in your browser; your XML is not uploaded.

Frequently asked questions

Does this validate my XML as well as format it?+

It checks that the XML is well-formed and shows "Error: Invalid XML" if not. For the parser's specific message, use the XML Validator.

Can I use this for RSS feeds or sitemaps?+

Yes. Any well-formed XML document works, including feeds, sitemaps, and configuration files.

Why is my <?xml ... ?> declaration missing?+

The formatter serializes only the root element, so the declaration and any comments outside the root are left out. Add the declaration back by hand if needed.

What indentation does it use?+

Two spaces per level. The indent size cannot be changed.

Related tools