XML Formatter — beautify & pretty-print XML
Paste minified or messy XML and watch it reformat instantly with clean indentation — 2 spaces, 4 spaces or tabs — plus syntax highlighting and a collapsible tree view of the document structure. Malformed XML gets the parser's error with its line and column, and Minify compresses everything back to a single line whenever you need it small.
Try an example
One click loads a realistic document and formats it — a starting point for testing feeds, configs, envelopes and graphics.
Your session
Snapshots and pinned setups live only in this tab's memory — close or reload the page and they are gone, so your XML is never stored. The tools rail remembers only which tools you opened in this tab (session storage, no XML data).
Format history
- No snapshots yet — format valid XML and it will appear here.
Favorite setups
- No pinned setups yet. Pin the current indent, attribute order and view to reuse them in one click.
Favorite tools
- Pin a tool below and it will appear here.
Recently used
- No other tools used yet this session — tools you open from this page will appear here.
All encoding & conversion tools
How to format XML
- Paste your XML into the box, or use Open .xml file to load one from your device — the file is read locally, never uploaded.
- The formatter checks that the document is well-formed and pretty-prints it instantly. Pick 2 spaces, 4 spaces or Tab indent, and optionally Sort attributes A–Z.
- Copy the result, download it as a .xml file, explore the structure in the Tree view, or press Minify to compress it back to one line.
Worked example
This 116-character minified input:
formats with 2-space indent to 138 characters across 7 lines:
The stats under the tool report 5 elements · 1 attribute · 3 text values · max depth 3 (the root element is level 1). Pressing Minify returns exactly the original 116 characters — formatting and minifying are both lossless for element-only content like this.
What formatting changes — and what it never does
| Part of the document | Effect of formatting |
|---|---|
| Indentation | Rebuilt from scratch: one element per line, nested by depth. This is the only change in default mode. |
| Text content | Untouched. An element holding only text stays on one line with its text exactly as written. |
| Mixed content | Elements that mix text and child elements (common in XHTML and DocBook) are kept fully inline — inserting line breaks there would add real spaces to the text, so the formatter never does it. |
| Attributes | Order and values preserved by default. Choosing Sort attributes A–Z reorders them alphabetically on every element — handy for diffing two config files. |
| Comments, CDATA, declaration | Preserved. Comments and processing instructions get their own line at the correct depth; CDATA sections are never escaped or split; a leading <?xml … ?> declaration stays at the top. |
| Minify | Removes whitespace that sits between elements, producing the smallest one-line form — ideal for payloads, feeds and embedded config. |
Reading the error messages
When XML is not well-formed, the status line shows the parser's own message, including the line and column where parsing failed. The classic case is a mismatched closing tag:
Here <title> is closed with </book>, so the parser stops at that closing tag and names the tag it expected. Other frequent fixes: close every tag (or use the self-closing form <tag/>), keep exactly one root element, quote every attribute value, and escape a raw & as & and a raw < in text as <.
What to do with your formatted XML next
Formatted XML is usually a waypoint, not the destination. The Send formatted XML to… bar under the output carries the current result into the next tool for you:
- Escape it for embedding — send it to the HTML Encoder/Decoder when XML has to sit inside an HTML page, an email or documentation without the browser interpreting the tags.
- Encode it for transport — Base64 for embedding in headers, tokens or data URIs, or the URL Encoder/Decoder when a payload has to travel inside a query string.
- Cross-check the structure — the JSON Formatter and JSON Validator cover the JSON side of an API workflow when the same service speaks both formats.
- Keep a reference offline — download the cheat sheet from the tool above: well-formedness rules, the five entities, CDATA and indent guidance in one text file, with your current document as the worked example.
Working the other way? Decode a Base64 payload or unescape HTML-encoded markup first, then chain the result back here to format and validate it.
Frequently asked questions
What does an XML formatter do?
It takes XML in any shape — minified onto one line, or messy with inconsistent spacing — and rewrites it with consistent indentation, one element per line, so the structure is easy to read, compare and debug. This formatter can also do the reverse (minify), sort attributes A–Z, and show the document in a collapsible tree view.
Why is my XML invalid?
The most common causes are mismatched or unclosed tags, more than one root element, unquoted attribute values, a raw ampersand or less-than sign in text (write & and < instead), and text before the root element. This formatter reports the parser's error message with the line and column where parsing failed.
Does formatting change my XML data?
No. Formatting only changes the whitespace between elements. Tag names, attribute values, text content, comments, CDATA sections and the XML declaration are preserved. Mixed content — elements that combine text and child elements — is kept inline exactly as written so no meaningful spaces are added or removed. Minifying is equally careful: it removes only whitespace that sits between elements.
What is the difference between well-formed and valid XML?
Well-formed means the document follows XML's syntax rules: one root element, properly nested and closed tags, quoted attributes. Valid means it also matches a schema or DTD that defines which elements and attributes are allowed. This tool checks well-formedness, which is what browsers and parsers require before anything else can process the file.
Should I use 2 spaces, 4 spaces or tabs to indent XML?
Two spaces is the most common default in editors and formatters. Four spaces can read easier in deeply nested documents like SOAP envelopes or build files, and tabs let every viewer pick their own visual width. Any consistent choice is fine — the data is identical either way.
Is my XML uploaded or stored?
No. Parsing and formatting happen entirely in your browser with JavaScript — nothing is uploaded, stored or tracked, so it is safe for config files, feeds and API payloads. Avoid pasting live secrets into any online tool as a general habit, but here nothing leaves your device.
Can I send formatted XML straight to other tools?
Yes. Use the Send formatted XML to… bar under the output: it carries the current formatted result in the link to the HTML Encoder/Decoder, JSON Formatter, JSON Validator, Base64 or URL encoder, so you can encode, check or convert it without copying and pasting. Very long documents are copied to your clipboard instead.
Does this page remember my XML between visits?
No. History snapshots, pinned setups and the recently-used tools list live only in this tab's session memory and disappear when you close or reload the tab. Your XML itself is never written to storage, uploaded or tracked — close the tab and it is gone.
Related encoding & conversion tools
About this tool
The XML Formatter is one of 33 free utilities in the Online Utilities Suite at dev.conversiontools.online. It parses with the browser's own strict XML parser — the same well-formedness rules real applications apply — and its pretty-printer is mixed-content safe, so formatting a document never changes what the document says. Every tool in the suite runs entirely in your browser, so results are instant and private even on large files.
Privacy
This page processes everything locally in your browser: no account, no uploads, and nothing you paste is stored or sent to a server. Files you open are read on your device only. Advertising on this site is served by Google AdSense, which may use cookies to personalize ads; you can opt out of personalized advertising in your Google ad settings.