XML Formatter & Beautifier

Paste XML, hit Format — clean indentation or one compact line, right in the editor. Runs 100% in your browser.

All computations run locally in your browser, no data uploaded to server.

How To Use

  1. Paste your XML into the editor, click Load file, or drag a .xml / .txt file onto it.
  2. Pick the Indentation: 2, 3, or 4 spaces to beautify — or just click Minify to collapse everything onto one line (it leaves the Indent selection untouched; Alt+Shift+M works too).
  3. Optionally enable Remove comments to strip <!-- --> blocks.
  4. Click Format (or press Ctrl+Enter / Cmd+Enter) — the editor content is rewritten in place. Undo appears and restores the previous version after either Format or Minify.
  5. Copy and Download hand you exactly what the editor shows — nothing more, nothing less.

The Demo button fills a realistic WebService-style sample and formats it instantly. On an error the editor never loses your text — you get the offending line and column and can fix it right where it is.

Usage Example

Turning a messy, inconsistently indented document into a clean tree — in place, right in the editor. Values keep their exact string form (no numbers are reinterpreted), and the comment survives unless Remove comments is on:

Messy XML input

<order id="A-1024"><customer>Alice</customer><items>
  <item>Widget</item><item>Gear</item>
</items><!-- rush order --></order>

After Format (2 spaces)

<order id="A-1024">
  <customer>Alice</customer>
  <items>
    <item>Widget</item>
    <item>Gear</item>
  </items>
  <!-- rush order -->
</order>

Formatting is idempotent: formatting the formatted content again changes nothing, which makes it safe to run repeatedly while you edit. Invalid input keeps your text in the editor and reports the exact spot, e.g. Invalid XML: Unclosed tag 'order'. (line 3, column 1).

Frequently Asked Questions

How do I format (beautify) XML online?

Paste your XML into the editor (or drag in a .xml / .txt file, or click "Load file"), pick an indentation width, and click Format. The editor content itself is rewritten in place with consistent indentation — messy mixed spacing becomes a clean tree in one click. Press Ctrl+Enter (Cmd+Enter on a Mac) to format without reaching for the button. Made a mistake? Undo restores exactly what was there before.

How do I minify or compress XML?

Click the Minify button (or press Alt+Shift+M in the editor): all inter-element whitespace and indentation collapses to nothing, producing one compact line that is cheaper to send over the wire. Minify does not touch your Indent selection — pick 2/3/4 spaces there and Format keeps using it. Text inside elements is never touched — "x y" stays "x y". The status line tells you exactly how many characters you saved. You can also choose "Minified" in the Indent select and click Format — both paths produce the same output.

Is my XML uploaded to a server?

No. This formatter runs 100% in your browser — the file you load is read locally with the browser FileReader, the formatted result is produced locally, and the download never makes a network request. You can disconnect from the internet and the tool keeps working. Nothing you paste or load is ever transmitted or stored on a server.

Why is my XML invalid? (common causes)

The four most common causes, all of which this tool pinpoints with a line and column: (1) an unclosed tag — every <tag> needs its </tag> (or a self-closing <tag/>); (2) mismatched case — XML tags are case-sensitive, so <Name> cannot be closed by </name>; (3) unquoted attribute values — id=7 is invalid, id="7" is required; (4) more than one root element — a document must have exactly one top-level element wrapping everything else. On an error the editor keeps your text untouched, so nothing is lost.

What is the XML declaration (<?xml … ?>) and is it required?

It is the optional first line (<?xml version="1.0" encoding="UTF-8"?>) that declares the XML version and character encoding. It is not required — XML works without it — and it must be the very first thing in the document if present. This formatter preserves it and re-emits it at the top of the output.

How are comments and CDATA sections handled?

Comments (<!-- … -->) are preserved and re-indented with the rest of the document; the "Remove comments" option strips them when you want clean output for comparisons or diffs. Either way the tool tells you what it did. CDATA sections (<![CDATA[…]]>) keep their content byte-for-byte — special characters inside never need escaping.

What file size and type limits apply?

Loaded files may be up to 2 MB (.xml or .txt) — the limit exists to keep the in-browser editor responsive, and the error message states the exact number when a file exceeds it. Typed/pasted input is accepted up to 8 MB. Everything runs locally, so nothing about your file size is ever reported anywhere.

Can I convert XML to JSON instead of formatting it?

Yes — use the separate XML to JSON Converter for that: it maps XML to JSON in both directions, with attribute and namespace handling built for SOAP/WebService payloads. This page deliberately does only formatting and minifying, so each tool stays focused on one job.