XML Beautify Formatter
Pretty-print XML with two-space indentation — text-only elements stay on one line, nested elements open up.
XML from APIs, feeds and config exports usually arrives as one unbroken line or with the generator’s arbitrary indentation, and both forms hide the tree. This formatter rebuilds the layout from the structure: it tokenises the document — elements, closing tags, self-closing tags, text, comments, CDATA sections, the XML declaration and doctypes — then prints two spaces per level of nesting. The smallest useful example: <a><b>1</b></a> comes out as three lines, with <b>1</b> indented inside <a>. An element whose only child is text stays on one line with that text (<price>9.99</price>), because splitting it across three lines would add noise without adding structure; an element with element children opens up, one child per line.
Formatting runs in this browser only — your XML is never uploaded, stored or put into a link. Indentation is two spaces per level. An element holding only text stays on one line with its text; elements holding other elements are opened up one child per line.
Quick answers
How do I format XML online?
Paste the document into a formatter and it re-indents by nesting depth — here two spaces per level. “<a><b>1</b></a>” comes out as three lines with <b>1</b> indented inside <a>.
Elements holding only text stay on one line (<price>9.99</price>); only elements with element children open up. Formatting shows structure — it does not validate the document.
What indent do XML formatters use?
Two spaces per level is the common default (it is what this page uses); some teams prefer four or a tab. Consistency with the surrounding project matters more than the choice itself.
Deep documents argue for two spaces: at ten levels of nesting, four-space indentation pushes content 40 columns across before it starts.
How to use
- Paste your XML into the top box — a compact API response, a config file, a feed.
- Read the formatted result below: two spaces of indentation per nesting level.
- Elements holding only text (like <title>Emma</title>) stay on one line; elements holding elements open up, one child per line.
- Copy the result. If the structure looks wrong, that is the formatter showing you the nesting as written — a mismatch was already there.
About this tool
Two honest boundaries. First, the formatter assumes well-formed input: it matches opening and closing tags as written and does not validate against a schema or DTD, so it will lay out a document whose nesting is technically balanced but semantically wrong exactly as happily as a correct one — formatting reveals structure, it does not certify it. Second, mixed content (text and elements interleaved, as in XHTML paragraphs) is printed with each child on its own line; that is a common formatter choice, but if your XML is really marked-up prose, prefer a formatter built for documents. Attribute values containing a literal > character are outside what this lightweight tokeniser handles.
Frequently asked questions
Why does <title>Emma</title> stay on one line while other elements open up?
Because an element holding only text has no inner structure to reveal — three lines for it would be pure noise. The rule here: element children get one line each, indented; a lone text child stays inline with its element. It is the layout most XML formatters converge on, and it keeps leaf values scannable in a long document.
Does the formatter validate my XML?
No. It tokenises and re-indents, assuming the document is well-formed. It does not check tag balance beyond laying out what it finds, and it knows nothing of schemas or DTDs. If your XML has a genuinely unclosed tag, get a validator’s error message first, fix it, then format.
What happens to comments, CDATA and the XML declaration?
All three are preserved and printed on their own lines at the correct depth: the <?xml …?> declaration first, comments as written, and CDATA sections with their contents character-for-character — the formatter never reaches inside a CDATA block to tidy it.
Is my XML uploaded anywhere?
No. The formatting is plain JavaScript in this page; your document — config files, API payloads, anything — never leaves your device, and there is no share link for pasted code on this site.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.