XML Formatter & Minifier
Beautify messy XML with clean indentation or minify it to one line, validated in your browser — with well-formed versus valid explained.
Indenting XML inserts text — it does not just move it
XML has no concept of insignificant whitespace unless a schema supplies one. Every newline and space a formatter adds between tags becomes a real text node in the document, and whether that matters depends entirely on what is inside the element:
| Input | Text content before | ...and after | Verdict |
|---|---|---|---|
<a><b>1</b><c>2</c></a> | "12" | "1 2" | safe |
<name> Ada </name> | " Ada " | "Ada" | padding lost |
<p>Hello <b>world</b>!</p> | "Hello world!" | "Hello world !" | corrupted |
<t>a<i>b</i>c</t> | "abc" | "a b c" | corrupted |
The first row is the case people have in mind, and it genuinely is safe — every leaf value comes through byte-identical. The parent element gains whitespace it did not have, but nothing reads a parent's text when its children are elements.
The last two rows are not safe. <p>Hello <b>world</b>!</p> means "Hello world!" and formats into
something that reads as "Hello world !", with the exclamation mark adrift. The
sharpest version has no spaces in it at all: <t>a<i>b</i>c</t> means
"abc" — one word — and comes out reading
"a b c", which is three.
<t> a <i>b</i> c </t>
Which is what separates a formatter from a find-and-replace
An element that mixes text with child elements cannot be indented at all without changing what
it says. A formatter that is safe has to detect that case and leave those elements on one line —
which is the difference between a real XML formatter and replacing
>< with >\n<.
It matters most in exactly the formats where it is most tempting. Anything HTML-like, anything with inline emphasis inside a paragraph, SVG with text, and most document formats are mixed content throughout. Configuration files and data exports usually are not, which is why formatting XML feels safe until the first time it is not.
One case where even the safe row is not safe: if a document has been digitally signed or its hash recorded, reformatting invalidates it, because the signature covers the bytes and the bytes changed. Canonical XML exists precisely to give a signable form that survives reformatting, and it is worth knowing about before you tidy up a signed document.
A smaller thing worth knowing while you are here. XML defines five entities and the usual assumption is that all five are mandatory everywhere. Only 2 are required in ordinary text:
| Character | Entity | Required in text | In an attribute | When |
|---|---|---|---|---|
& | & | yes | yes | always |
< | < | yes | yes | always |
> | > | no | no | only inside ]]> |
" | " | no | yes | only in a double-quoted value |
' | ' | no | no | only in a single-quoted value |
Escaping the other three is conventional and harmless. It is worth knowing mainly because
people write validators that reject a document for containing a bare >, which is
perfectly well-formed XML — the greater-than sign only has to be escaped inside the sequence
]]>, and nowhere else.
How to use
- Paste your XML.
- Choose beautify or minify.
- Read the error position if parsing fails.
- Copy or download the result.
Frequently asked questions
What is the difference between well-formed and valid XML?
Well-formed means the syntax is correct — tags closed, properly nested, one root element. Valid means it additionally conforms to a schema defining which elements may appear where. All valid XML is well-formed; well-formed XML may still be wrong for its purpose.
Why is XML stricter than HTML?
By design. HTML parsers recover from unclosed tags and mismatched nesting because the web is full of imperfect markup. XML refuses, on the principle that silently guessing at malformed data is worse than failing loudly — a decision that makes XML more predictable and less forgiving.
What is a CDATA section?
A block whose contents the parser does not interpret as markup, so angle brackets and ampersands inside it are literal text. It is the usual way to embed code or arbitrary text in an XML document without escaping every special character.
What are namespaces for?
Preventing name collisions when documents from different vocabularies are combined. Two schemas may both define a title element meaning different things; a namespace prefix keeps them distinct. The syntax is notoriously fiddly and a frequent source of confusion.
Does indentation change the meaning?
It can. Unlike JSON, XML treats whitespace inside an element as content, so adding indentation technically alters the text nodes. Most consumers ignore whitespace-only nodes, but a strict one processing mixed content may not, so reformatting is not always perfectly safe.
Is XML obsolete?
No, though JSON has replaced it for most web APIs. XML remains standard in publishing, office document formats, SVG, RSS, financial messaging and enterprise integration — anywhere schemas, namespaces and validation matter more than compactness.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.