Saved

Press the star next to a tool's name to save it.

All my tools

XML Beautifier

This XML beautifier formats XML with clean indentation, keeps short values inline, checks it's well-formed first, and can also minify it to one line.

The XML is checked first. If it isn't well-formed, you'll see the line, column and problem to fix.

Your XML is formatted in your browser. Nothing is uploaded.

Formatted XML

Paste XML and press Format XML.

An XML beautifier turns cramped or messy XML into neatly indented, readable code. Paste your XML and this XML beautifier puts each element on its own line, indents child elements under their parents, and keeps short values on one line with their tags. Choose 2 spaces, 4 spaces or tabs, or switch to Minify to squeeze the XML onto a single line. Copy the result or download it as an .xml file.

Why beautify XML?

XML from APIs, exports, feeds and configuration files often arrives on one long line, or with uneven indentation from hand editing. That makes it hard to see which element sits inside which, or to spot a missing value. Beautified XML shows the structure at a glance: every level of nesting is indented one step further, so parents, children and siblings line up.

It checks the XML first

The beautifier only formats well-formed XML. A well-formed document follows the XML 1.0 syntax rules: content is delimited by start and end tags, elements are properly nested with none overlapping, tags are case-sensitive and must match exactly, attributes are in quotation marks, there's a single root element, and special characters such as < and & appear only as markup. The XML specification requires a processor that finds a violation to report it and stop, so this tool does the same: it shows the line and column of the first problem and explains it, for example a closing tag that doesn't match or an attribute without quotes.

How the formatting works

  • One tag per line, indented by its depth in the tree.
  • Short text stays inline, so <title>XML Basics</title> stays on one line.
  • Empty elements such as <br/> or <item></item> stay on one line.
  • Comments, CDATA sections, processing instructions and the DOCTYPE are kept exactly as written, each on its own line.
  • Attributes are kept as written, in their original order.
  • Whitespace between tags is removed and replaced with the new indentation, and the text inside elements is trimmed.

Beautify or minify?

Beautify for reading, reviewing and editing. Minify for sending or storing: it removes the whitespace between tags so the file is smaller, which helps for large feeds or when XML is embedded in another file. The data itself is the same either way.

How to use the XML beautifier

  1. Paste your XML into the box.
  2. Choose Beautify or Minify, and for Beautify pick 2 spaces, 4 spaces or tabs.
  3. Press Format XML. If there's a problem, fix the line shown and try again.
  4. Copy the result or download it as an .xml file.

Example

This one-line XML:

<catalog><book id="b1"><title>XML Basics</title><price currency="USD">19.99</price></book></catalog>

becomes six lines: catalog, then book indented one step, then title and price indented two steps with their values on the same line, then the closing book tag indented one step and the closing catalog tag.

When whitespace matters

In most data XML, the spaces and line breaks between tags don't matter, so reformatting is safe. In documents with mixed content, where text and tags are interleaved inside a paragraph, or where an element is marked to preserve spaces, trimming whitespace can change the meaning. For those, keep the original or check the result carefully. To check XML without changing it, use our XML validator.

Choosing an indent

Two spaces keep deeply nested XML compact and are common in configuration files and web projects. Four spaces make each level stand out more and suit documents with only a few levels. Tabs let each person's editor decide how wide an indent looks. If you're editing a file that's shared with other people, match the style already used in the project so changes are easy to compare. You can switch between the options after formatting and the result updates straight away.

Where XML still shows up

  • Web feeds: RSS and Atom feeds for blogs and podcasts.
  • Sitemaps: the sitemap.xml files that list a site's pages for search engines.
  • Office files: the documents inside .docx and .xlsx files are XML.
  • Configuration: settings files for many applications and build tools.
  • Data exchange: invoices, bank files and APIs that use SOAP or other XML formats.
  • Graphics: SVG images are XML, so you can tidy their code here too.

Large files

The beautifier works on files up to 5,000,000 characters, entirely in your browser, so very large files may take a moment. If your file is bigger, split it into sections, or use Minify to make it smaller before storing it. The statistics under the result show how many lines and characters the output has.

Common mistakes

  • Unescaped ampersands. Write &amp; for a plain &.
  • Mismatched case. <Book> and </book> don't match.
  • Two root elements. Wrap them in a single parent.
  • Unquoted attributes. Every attribute value needs quotes.

What next

Use this often? Add XML Beautifi to your Home screen.

Frequently asked questions

How does the XML beautifier work?

It checks that your XML is well-formed, then puts each tag on its own line, indents children under their parents and keeps short values inline.

Can it minify XML too?

Yes. Choose Minify to remove the whitespace between tags and put the XML on one line.

Why won't my XML format?

It isn't well-formed. The tool shows the line, column and problem, such as a mismatched closing tag or an unquoted attribute.

Does the XML beautifier change my data?

Element names, attributes, comments and CDATA are kept. Whitespace between tags is replaced and text inside elements is trimmed.

Is my XML uploaded?

No. Formatting happens in your browser and nothing is sent anywhere.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools