XML Formatter

Indent messy XML so it is easy to read, or minify it to a single line. Comments, CDATA, and the XML declaration are kept exactly as they are.

Updated
Runs in your browser. Your data is not uploaded.
Mode
Formats as you type for inputs up to 200 KB.

How to use the XML Formatter

  1. Paste XML into XML input, upload an .xml file, or drop one onto the box.
  2. Choose Beautify or Minify, and the Indent for beautified output.
  3. Press Format, then copy the result or download it as a file.

How it works

The formatter reads the XML into a tree, checks that it is well-formed, and writes it out again.

  • Beautify puts each element on its own line, indented one level deeper than its parent. An element that holds only text stays on one line: <name>Ada</name>.
  • When an element mixes text and child elements, like <p>Hello <b>world</b></p>, its content is left as written, because adding line breaks there would change the text.
  • Minify removes the whitespace between tags. Whitespace inside text is kept.
  • Attribute values, entities such as &amp;, comments, and CDATA sections are copied without change.

Examples

Input:

<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price currency="USD">29.99</price></book></catalog>

Beautified with 2 spaces:

<?xml version="1.0"?>
<catalog>
  <book id="b1">
    <title>XML Basics</title>
    <price currency="USD">29.99</price>
  </book>
</catalog>

Minifying the beautified version gives back the one-line input.

Limitations

  • The input must be well-formed XML. HTML with unclosed tags such as <br> is rejected; use the HTML Formatter for HTML.
  • The formatter doesn't validate against a DTD or XSD schema.
  • Files are limited to 5 MB.
  • Attribute order and quote style are kept, but line breaks inside a start tag are replaced by single spaces.

Frequently asked questions

Will formatting change my data?

No. Only whitespace between tags changes. Text, attributes, comments, and CDATA stay exactly as they were, and mixed text content is not reflowed.

What is the difference between beautify and minify?

Beautify adds line breaks and indentation so people can read the XML. Minify removes that whitespace to make the file smaller for storage or transfer.

Why does my XML fail to format?

It is not well-formed. Common causes are a missing closing tag, an unescaped &, or unquoted attribute values. The error shows the line and column; the XML Validator explains the fix.

Is my XML uploaded?

No. Formatting runs in your browser.

Often used together with the XML Formatter.

  • XML Validator

    Checks XML for well-formedness and explains each syntax error.

  • HTML Formatter

    Beautifies HTML with consistent indentation, including inline CSS and JavaScript.