XML Formatter

Paste XML and pick easy to read or one line. The XML is checked first, so if it is broken you see the line and column of the problem instead of a layout that hides it.

How it works

First, your browser's own XML parser reads the document. If it is not well-formed, for example a tag is not closed, the tool shows the line and column where the parser stopped, and formats nothing.

Easy to read puts each element on its own line, indented two spaces per level. An element that holds only text stays on one line, such as <name>Tea</name>. Compact removes the whitespace between tags and puts the document on one line.

Only whitespace between tags is changed. Text is data in XML, so text, mixed content such as a paragraph with a bold word, CDATA sections and anything under xml:space="preserve" are written back exactly. The work happens on this page, and your XML is not uploaded.

How to use it

  1. 1 Pick Easy to read or One line.
  2. 2 Paste your XML into the first box. The result appears in the second box as you type.
  3. 3 If the XML is broken, read the line and column under the box, fix it, and the result appears.
  4. 4 Press Copy result, or download it as a .xml file.

Good to know

  • The XML declaration, comments, processing instructions and the DOCTYPE are kept in place.
  • Spaces between attributes are tidied to one space. Attribute values are not touched.
  • To check a file without changing it, use the XML Validator. It gives the same line and column.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Formatting an order file without touching its text

Take a small order exported as one line: an XML declaration, then <order id="7">, which holds an <item sku="A1"> with a <name> of Tea and a <qty> of 2. After the item comes a <note> that says "Leave it by the door", with "by" in bold. It is all on one line, so the structure is hard to see at a glance.

Before laying anything out, the tool hands the text to your browser's XML parser. This one is well-formed, so formatting goes ahead. The declaration stays on the first line. <order id="7"> goes on the next line, and the item is indented two spaces below it. Inside the item, <name>Tea</name> and <qty>2</qty> each get one line, indented four spaces. Elements that hold only text stay on one line, because splitting them would add spaces and line breaks to the text itself. Then </item> closes the block, the note comes next, and </order> ends the file. One line has become eight.

Look at the note. It reads <note>Leave it <b>by</b> the door</note>, still on one line, exactly as it came in. The note holds both text and an element, which XML calls mixed content. In mixed content the spaces around <b>by</b> are part of the sentence. If the formatter put <b> on its own line, a program reading the file would see "Leave it", a line break, and some spaces before "by". So mixed content is written back as it is. The same goes for CDATA sections and any element marked xml:space="preserve".

Now break the file. Change the closing tag of the item to </itme>. The parser stops at that line and the tool shows the line and the column where it stopped, with the browser's own message, which says the end tag does not match. Nothing is formatted, so you never see a neat layout of a broken file. Fix the tag and the formatted XML comes back. One line works the same way: it removes the whitespace between tags, keeps the text, and shows how many bytes it saved.

There are limits. The check is for well-formedness only. The tool does not read your XSD schema or DTD, so a document with a misspelled element name that still matches its own closing tag passes. The exact wording of the error message comes from your browser, so Chrome, Firefox and Safari word it differently. And the formatter assumes that whitespace between elements is layout, not data. That is true for almost all data files, but a few formats treat it as content, and for those you should keep the original.

Frequently asked questions

Why will it not format my XML?

Because the XML is not well-formed, and the message under the box says where. Common causes are a tag that is not closed, a closing tag spelled differently from its opening tag, and a bare & in text, which must be written &amp;. Formatting broken XML would hide the error inside a layout that looks right, so the tool shows the error instead.

Will formatting change my data?

It only changes whitespace between tags. Text inside elements, CDATA and anything under xml:space="preserve" is written back exactly. If your program treats whitespace-only text between elements as data, which is rare, use One line or keep the original.

Does it validate against a schema or DTD?

No. It checks that the XML is well-formed: tags match, attributes are quoted, and entities are valid. It does not check the document against an XSD schema or a DTD.

Can I indent with tabs or four spaces?

Not on this page. The output uses two spaces per level, which most editors can convert if you need something else.

Is my XML sent to a server?

No. The browser's built-in XML parser checks it and JavaScript on this page formats it. Nothing you paste leaves your device.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.