TL;DR: This is a free XML formatter that runs entirely in your browser. Paste XML, choose 2-space, 4-space or tab indentation, and press Format XML. If the document is malformed you get the exact line and column plus a plain-English explanation — and nothing is ever uploaded.
XML is deliberately verbose, and hand-edited XML drifts fast: indentation becomes inconsistent, a closing tag gets renamed, an attribute loses its quotes. A formatter fixes the presentation, and a well-formedness check catches the structural mistakes before they reach a build, an API call or a config loader. This tool does both in one pass, and it does both locally.
The formatter parses the document with a small XML parser written for this site rather than leaning on a browser API. That is why it can point at the exact character that broke the file instead of repeating a one-line “XML parsing error”. When the XML is valid it re-indents every level, normalises spacing around attributes, and leaves the data alone: text nodes, comments, CDATA sections and entity references come out exactly as they went in.
How to format XML with this tool
Paste your XML
Click the left pane and paste from your editor or clipboard. The size counter in the pane header turns red above the 2 MB cap before you run anything.
Choose an indent
Two spaces is the default. Four spaces and one tab are one click away in the Indent menu; changing the menu re-formats the document instantly so you can compare widths.
Press Format XML
The parser checks well-formedness first. Only a valid document is re-indented; an invalid one produces an error report instead of half-broken output.
Copy the result
Copy result puts the formatted XML back on your clipboard. Clear empties both panes, and Load sample fills the editor with a small catalog document if you just want to try the tool.
Keyboard shortcut: Ctrl + Enter on Windows or Cmd + Enter on macOS runs the page’s main action without reaching for the mouse.
What an XML formatter actually does
An XML formatter — also called an XML pretty-printer or XML beautifier — rebuilds the whitespace between markup so the document’s hierarchy is visible at a glance. It does not remove elements, rename tags, reorder attributes or change values. The output is the same document with different indentation.
The rules used here are intentionally conservative. Whitespace-only text nodes between child elements are replaced by real indentation. Elements that contain text stay on one line, and the text itself is copied byte for byte, so a document like <p>Hello <b>world</b>!</p> keeps its exact inline spacing. Comments, processing instructions, DOCTYPE declarations and CDATA sections are preserved, and attribute quotes stay single or double exactly as the input had them.
Formatting is idempotent: formatting the output again produces identical bytes. That matters if you plan to run the formatter routinely — before committing spring.xml, web.config or an Android resource file, for example — because a second run will not add noise to the diff. When you need the opposite operation, the XML Minifier removes indentation instead of adding it.
How this formatter reports errors
Most browser-based XML checkers hand the document to a browser parser and print whatever that parser says. Chrome, Firefox and Safari word the same problem differently, and the position is often missing or approximate. This formatter uses its own tokenizer and parser, so the wording is consistent across browsers and the line and column are always present.
Every error has the same shape: a location, a plain-English explanation and a short fix hint. The parser also prints a two-line code frame with a caret under the offending character, which matters when several attributes sit on one long line. Only the first five errors are shown at a time — fix them, run again, and the report continues from there. If you only need the check and not the reformatting, the dedicated XML Validator page runs the same parser and adds a structural report.
| Problem | Message you will see | How to fix it |
|---|---|---|
| Mismatched closing tag | Line 9, Column 5 — Closing tag </titl> does not match the open <title> tag (opened on line 7). | Correct the spelling of the closing tag; XML names are case-sensitive. |
| Unclosed element | Line 5, Column 3 — <body> (opened on line 5, column 3) is never closed. | Add </body> before the parent closes, or write <body/> if it is empty. |
| Unquoted attribute | Line 2, Column 9 — Attribute value must be quoted. Write id="1" instead of id=1. | Wrap every attribute value in single or double quotes. |
| Raw ampersand in text | Line 2, Column 13 — A literal “&” must be escaped as &. | Escape the ampersand, or move the text into a CDATA section. |
| Unknown entity | Unknown entity “ ” — XML only defines the five predefined entities and numeric references. | Use   or paste the actual character. |
| Two root elements | Only one root element is allowed. Found a second root <b> after <a>. | Wrap both elements in a single container element. |
Choosing an indent width
There is no official XML indentation standard. Two spaces is the de-facto default in Maven POMs, Spring bean files and most .NET configuration; four spaces is common in Android resource files; tabs are what xmllint produces by default and what many Vim and Emacs users prefer. What matters is that a repository is consistent, because mixed indentation turns every meaningful diff into a wall of whitespace changes.
Whichever width you choose, the formatter only touches whitespace between tags. If a text value intentionally begins or ends with spaces — an XML string that is later compared verbatim, for example — those spaces are preserved instead of trimmed.
Large files, privacy and browser limits
Everything runs in the tab you are looking at. Your XML never reaches a server, so the tool also works with sensitive configuration files, and it keeps working offline after the page and its assets have loaded once. The trade-off is memory: a browser tab has far less of it than a command-line tool, so input is capped at 2 MB (2,097,152 bytes). Anything larger is refused immediately — the tool tells you the exact size, explains the cap and suggests splitting the file or using a desktop editor. Refusing early is deliberate: parsing a 20 MB document on the main thread is how an online formatter earns a reputation for freezing.
Two more guards protect against pathological documents: nesting deeper than 2,000 levels and documents with more than 150,000 elements stop with a clear message instead of exhausting the tab’s memory.
XML formatter tools in this topic
This page is the main guide for the XML Formatter topic. The browser-based version of the same tool has its own page with a workflow-focused explanation:
- XML Formatter Online — format XML in any browser tab with no installation and no upload, using the same parser and the same error format as this page.
The other two topic guides are XML Validator for well-formedness checks and XML Minifier for whitespace removal.
Frequently asked questions
Is this XML formatter free?
Yes. Every tool on this site is free, has no account requirement, no usage limit and no paid tier. There is no advertising inside the editor and no upload.
Does the tool upload my XML to a server?
No. Formatting, minifying and validation are implemented in plain JavaScript that runs in your browser. You can open the browser's developer tools, switch to the Network tab and click Format XML: no request carries your document.
What is the difference between an XML formatter and an XML validator?
A formatter changes only indentation and spacing; a validator decides whether the document is well-formed XML. This page validates first and formats second, so it never gives you broken output to copy. The dedicated XML Validator page gives a fuller structural report.
Why does my XML fail to format?
The most common causes are a mismatched closing tag, an unquoted attribute value, a raw ampersand in text, a duplicate attribute or two root elements. The error report names the line, the column and the usual fix for each one.
Can it format very large XML files?
Inputs up to 2 MB (2,097,152 bytes) are formatted locally in the browser. Larger files are refused with an explanation so the page stays responsive. For multi-megabyte documents, use xmllint --format, a desktop editor or a build plugin.
Does formatting change my data?
No. Element names, attribute values, text content, comments, CDATA sections and entity references are preserved exactly. Only whitespace between tags and spacing between attributes is normalised.
Does it check my XML against an XSD or DTD schema?
No. The checker verifies that the document is well-formed XML; schema validation is a separate and stricter step that requires the schema file. xmllint --schema is the usual command-line way to do that.
Related XML tools
XML Formatter Online
Format XML online in any browser — no install and no upload.
Open →XML Validator
Check XML and get exact line and column errors in plain English.
Open →XML Minifier
Strip whitespace and indentation to shrink XML files.
Open →About
Who runs this site and how the tools are built and tested.
Open →