Free online tools
English EN, Choose a language

XML formatter

Paste XML to indent it with 2 or 4 spaces or tabs, minify it, and see the line of any well-formedness error.

Action

Indent

Result

Paste XML and the formatted result appears here.

Runs in your browser. Your XML is never uploaded or stored.

How to format XML online

  1. Paste your XML into the box, or press Insert example.
  2. Choose Format and an indent (2 spaces, 4 spaces or a tab), or Minify to strip the whitespace between tags.
  3. Copy the result or download it as a .xml file. Use as input moves the result back into the box.

The page checks that the XML is well-formed before it prints anything. If it is not, you get the line, the column and the reason instead.

Format and minify: one example

XML as many APIs and exports deliver it, on one line:

<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price>9.99</price></book><book id="b2"><title>Data &amp; Tags</title><price>14.50</price></book></catalog>

Formatted with 2 spaces. Elements that hold only text stay on one line, so <title>XML Basics</title> is not split:

<?xml version="1.0"?>
<catalog>
  <book id="b1">
    <title>XML Basics</title>
    <price>9.99</price>
  </book>
  <book id="b2">
    <title>Data &amp; Tags</title>
    <price>14.50</price>
  </book>
</catalog>

Minified, with whitespace between tags and comments removed (text inside elements is kept, with runs of whitespace collapsed):

<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price>9.99</price></book><book id="b2"><title>Data &amp; Tags</title><price>14.50</price></book></catalog>

Formatting only adds or removes whitespace between tags. If your XML uses mixed content (text and tags in the same element, as in HTML-like documents), whitespace can be significant; check the result before you rely on it.

Well-formed errors and what they mean

XML is much stricter than HTML. These are the mistakes the checker finds, with the message it gives:

MistakeMessage
Tags closed in the wrong orderNot well-formed XML at line 3, column 9: closing tag </a> does not match <c> opened at line 3.
An element never closedNot well-formed XML at line 1, column 1: <a> is never closed.
Attribute value without quotesNot well-formed XML at line 1, column 1: attributes in <note to=Ann> need a name and a quoted value.
A bare ampersand in textNot well-formed XML at line 1, column 9: a bare & must be written &amp;.
Two root elementsNot well-formed XML at line 1, column 5: only one root element is allowed; <b> starts a second one.

The five characters that must be escaped in text are &amp; for &, &lt; for < and, in attribute values, &quot; for the double quote; &gt; and &apos; are optional. Anything else needs an escape only if it is not in your document's encoding.

What well-formed means, and what it does not

A well-formed document has exactly one root element, every start tag has a matching end tag in the right order (or is self-closing, like <br/>), attribute values are quoted, and special characters are escaped. This tool checks all of that.

It does not validate against a schema (XSD) or DTD, resolve entities such as &nbsp; that need a DTD (use &#160; instead), or check namespaces. A document can be well-formed and still be wrong for the system that reads it: for that you need the schema from that system.

The XML declaration (<?xml version="1.0"?>), comments and CDATA sections are kept as they are. To pretty-print JSON instead, use the JSON formatter; for text encoded as Base64 inside an XML element use Base64 decode.

Related tools

XML formatter FAQ

How do I format XML?

Paste the XML, keep Format selected and choose an indent. The indented result appears at once and can be copied or downloaded.

How do I check whether my XML is valid?

The tool checks that it is well-formed: one root, matching tags, quoted attributes and escaped ampersands. An error shows the line and column.

Does it validate against an XSD or DTD?

No. It checks well-formedness only. Schema validation needs the schema file and a schema-aware validator.

Why does my XML say "unexpected characters in a tag"?

A tag has something the parser cannot read, such as an unquoted attribute value or a stray less-than sign. Escape a literal < as &lt;.

Will formatting change the meaning of my XML?

For data-style XML no. Formatting only changes whitespace between tags. In mixed content (text next to tags) whitespace can matter, so check the result.

Is my XML uploaded anywhere?

No. It is checked and formatted in your browser and nothing is sent or stored.

Missing something in the XML formatter?Suggest an idea. It takes 20 seconds and we read every one.Suggest an idea

Sends only what you type here, never the text you work with. Your email is used only to reply about this idea.

Free online tools