XML formatter and beautifier

Paste XML to indent it neatly. The XML formatter also checks that the document is well-formed and reports the line and column of the first error.

  • Free
  • No sign-up
  • Runs in your browser

Runs in your browser — your text is never sent to our servers.

How to use XML Formatter

  1. Paste your XML into the input box, or click Open a file to load an .xml file.
  2. Choose 2 spaces, 4 spaces or a tab for indentation.
  3. Read the formatted XML in the output box; errors show the line and column.
  4. Click Copy or Download to save formatted.xml.

Features

  • Indents nested elements with 2 spaces, 4 spaces or tabs
  • Checks well-formedness and reports line and column
  • Keeps attributes, comments and the XML declaration
  • Keeps character entities such as & unchanged
  • Runs in your browser, so the XML is never uploaded

Supported formats and limits

  • Maximum input: 10,000,000 characters

Examples

InputResult
<?xml version="1.0"?><library><book id="1"><title>Dune</title></book><book id="2"><title>Emma</title></book></library><?xml version="1.0"?> <library> <book id="1"> <title>Dune</title> </book> <book id="2"> <title>Emma</title> </book> </library>
<a> <b></a>Invalid XML at line 2, column 4: Expected closing tag 'b' (opened in line 2, col 1) instead of closing tag 'a'.

Limitations

  • The formatter checks that XML is well-formed, but does not validate it against a DTD or XSD schema.
  • Whitespace between elements is reformatted. Text that depends on exact spacing inside an element may change.
  • Very large files may be slow to process in the browser.

Learn more

XML documents often arrive as a single long line, for example from an API or an export. That is fine for machines but hard for people to read. Formatting adds line breaks and indentation so the nesting of elements is visible.

Before formatting, the document has to be well-formed, which is the minimum requirement of the XML specification: one root element, properly nested and closed tags, quoted attribute values, and special characters such as & and < written as entities. A parser must reject a document that breaks these rules, and so does this tool, pointing at the line and column where it noticed the problem.

Well-formed is not the same as valid. Validity means the document also follows a particular schema, such as an XSD, which lists the allowed elements and their order. This tool does not check that.

Frequently asked questions

What does well-formed XML mean?

It has a single root element, every opening tag is closed, tags are nested correctly and attribute values are quoted. The validator checks exactly these rules.

Does it validate against a schema?

No. It checks well-formedness only, not a DTD or XSD.

Are comments and attributes kept?

Yes. Comments, attributes, the declaration and entities are kept as they are.

Is my XML uploaded?

No. Formatting runs in your browser.

Sources

Last reviewed: September 30, 2026