# XML formatter

> Format XML with clean indentation and check that it is well-formed, with the error line if not. Free, no sign-up, and nothing leaves your browser.

Canonical: https://toolspace.tech/xml-formatter/
Last updated: 2026-10-25

Format XML with clean indentation and check that it’s well-formed: a mismatched tag, a bare & or a repeated attribute is reported with its line and column. Minify mode strips comments and the whitespace between tags.

This is an interactive tool that runs in the browser: [open the XML formatter](https://toolspace.tech/xml-formatter/) to use it. Nothing typed into it is uploaded.

## Worked example

A small order document on one line.

**xml**

```
<?xml version="1.0"?><order id="7"><customer>Ada</customer><items><item sku="A1" qty="2"/><item sku="B2" qty="1"/></items><note>Leave at the  door</note></order>
```

**formatted**

```
<?xml version="1.0"?>
<order id="7">
  <customer>Ada</customer>
  <items>
    <item sku="A1" qty="2"/>
    <item sku="B2" qty="1"/>
  </items>
  <note>Leave at the  door</note>
</order>
```

The double space in the note is text, so it stays.

## Common mistakes

### A bare ampersand

“Tom & Jerry” must be “Tom &amp; Jerry”. Watch for it in URLs inside attributes: ?a=1&amp;b=2.

### HTML entities in XML

&nbsp;, &copy; and the like aren’t defined in XML. Use numeric references such as &#160; and &#169;.

### Two root elements

A document can have only one top-level element. Wrap a list of records in a single parent such as `<items>`.

### Tags that differ only in case

XML names are case-sensitive, so `<Item>`…`</item>` is a mismatch, not a match.

## How it works

1. **Paste or open XML:** A config file, a feed, a SOAP message or an SVG. Files are read in your browser.
2. **Pick a mode:** Format puts each element on its own line. Minify removes comments and the whitespace between tags. Choose 2 or 4 spaces or tabs.
3. **Fix any error:** If the XML isn’t well-formed, nothing is changed: you see the first problem and a button that jumps to its line.

## Questions

### What does well-formed mean?

One root element; every tag closed, in the right order and with the same case; attribute values quoted and not repeated; and & and < in text written as &amp; and &lt;. Any XML parser rejects a document that breaks one of these rules.

### Does it validate against a schema or DTD?

No. It checks well-formedness, not whether elements match an XSD or DTD. Entities declared in an internal DTD are accepted and left as they are.

### Will formatting change my text?

No. Only the whitespace between tags is changed, and only in elements that contain other elements and no text. Text, CDATA, comments, attribute values, mixed content (text next to tags) and anything under xml:space="preserve" stay exactly as written.

### Why is &nbsp; an “unknown entity”?

XML predefines only five entities: &amp; &lt; &gt; &quot; and &apos;. Write a no-break space as &#160;, or declare the entity in a DOCTYPE.

## Related

- [Code beautifier](https://toolspace.tech/code-beautifier/)
- [HTML beautifier](https://toolspace.tech/html-beautifier/)
- [JSON formatter](https://toolspace.tech/json-formatter/)
- [YAML validator](https://toolspace.tech/yaml-validator/)
