XML Formatter - Format & Beautify XML Online (Free)

Paste any XML and instantly format it with proper indentation. Free XML beautifier — runs in your browser, no upload, no sign-up required.

Input
323 chars · 1 lines · 323 bytes
Output

Paste messy XML and read it in seconds

Cramped, single-line XML is nearly impossible to debug. Paste it above and this XML formatter instantly indents every element so the structure is obvious at a glance — no sign-up, no upload, nothing to install.

Every byte stays in your browser. Your config files, API responses, and feed data never leave your machine.

Quick before → after

<!-- Before: hard to read -->
<order id="42"><item><name>Widget</name><qty>3</qty></item></order>

<!-- After: formatted -->
<order id="42">
  <item>
    <name>Widget</name>
    <qty>3</qty>
  </item>
</order>

One XML rule worth knowing: every tag must be closed, there must be exactly one root element, and tag names are case-sensitive (<Name><name>). Formatting only changes whitespace — your actual data is never altered.

How to use the XML formatter

  1. Paste your XML into the editor above.
  2. Click Format (or press the keyboard shortcut shown).
  3. Copy the indented output or download it as a file.

If your XML has a syntax error — a missing closing tag, for example — the tool highlights exactly where the problem is so you can fix it fast.

Worked example

Say you pull a product feed from an API and it comes back as one long string:

<catalog><product><id>101</id><name>Laptop Stand</name><price currency="USD">49.99</price><stock>true</stock></product></catalog>

After running it through the XML beautifier you get:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <product>
    <id>101</id>
    <name>Laptop Stand</name>
    <price currency="USD">49.99</price>
    <stock>true</stock>
  </product>
</catalog>

Attributes stay on their element, child nodes are indented two spaces, and the data is byte-for-byte identical to what you started with — just readable now.

Format XML in Python or JavaScript

Need to pretty-print XML in code? Here are the shortest working snippets for the two most common languages.

Python

import xml.dom.minidom

raw = '<catalog><product><id>101</id></product></catalog>'
pretty = xml.dom.minidom.parseString(raw).toprettyxml(indent='  ')
print(pretty)

The built-in xml.dom.minidom module ships with Python — no extra install needed. toprettyxml(indent=' ') uses two spaces per level.

JavaScript (Node.js)

// npm install xmlbuilder2
const { convert } = require('xmlbuilder2');

const raw = '<catalog><product><id>101</id></product></catalog>';
const pretty = convert(raw, { prettyPrint: true });
console.log(pretty);

The xmlbuilder2 library handles both parsing and serialisation. One npm install and you're done.

How it works

The formatter parses your raw text into a DOM tree (a structured map of every element and attribute). It then walks that tree and re-serialises it — writing each node on a new line with consistent indentation. No data is changed; only whitespace is added between tags.

The W3C defines the rules that govern well-formed XML — every formatter follows the same standard. You can read the official spec at w3.org/TR/xml.

When to use an XML formatter (and when not to)

Use it when…Skip it when…
Debugging API responses or config filesYou need to convert XML to JSON or CSV
Reading SOAP payloads or RSS/Atom feedsThe file is huge (100 MB+) — use a desktop editor instead
Reviewing SVG or XHTML markupYou need to validate against an XSD schema (use an XML validator)
Tidying Maven pom.xml or Android manifestsYour file is actually HTML — use an HTML formatter instead

Paste your XML above and get a clean, indented result right now — no account required.

Frequently asked questions

Is my XML data uploaded to a server?+
No. Everything runs directly in your browser using JavaScript. Your XML is never sent to any server, so sensitive config files, API keys inside payloads, and private data all stay on your machine.
What's the difference between an XML formatter, beautifier, and pretty printer?+
They all mean the same thing: taking compact or minified XML and adding indentation so it's easy to read. 'Formatter', 'beautifier', and 'pretty printer' are interchangeable terms for this operation.
Does formatting change my XML data in any way?+
No. Only whitespace between tags is added or adjusted. Every element name, attribute, and value is written back exactly as it was. The formatted XML is semantically identical to the original.
How do I format XML in VS Code?+
Open your .xml file in VS Code, then press Shift+Alt+F on Windows/Linux or Shift+Option+F on Mac. VS Code has a built-in XML formatter, and the 'XML' extension by Red Hat adds extra features like schema validation.
Why does the formatter show an error on my XML?+
XML must be 'well-formed' — every opened tag must be closed, there must be a single root element, and attribute values must be quoted. The most common errors are a missing closing tag (e.g. with no ) or an unescaped & character (write & instead).
Can the tool handle large XML files?+
It works well for files up to a few megabytes. Very large files (50 MB+) can slow down or freeze a browser tab because everything is processed in memory. For those sizes, use a desktop editor like VS Code or XMLSpy.
Does this tool also validate my XML?+
It checks that your XML is well-formed (correct tag structure, proper nesting) as a side effect of parsing it. It does not validate against an XSD or DTD schema — for that you need a dedicated XML validator.
Is this tool free? Do I need to create an account?+
Completely free, no account needed. Paste your XML, hit Format, and copy the result — that's it.