Report a problem

XML Formatter Online

Beautify XML with 2 or 4-space indentation, validate it against the browser's strict XML parser with line and column error reporting, or minify it for transmission. Free, no sign-up, runs entirely in your browser.

Your XML never leaves your browser

Formatting, validation and minification run locally in plain JavaScript. Nothing is uploaded or logged.

Validation-
Input size0 B · 0 lines
Output size0 B · 0 lines

Comments, processing instructions, DOCTYPE and CDATA sections are preserved in both modes. CDATA content passes through byte-for-byte.

What this XML formatter does

This online XML formatter takes a document that arrived as a single line from an API response, a SOAP envelope or a generated config file, and rewrites it so the tree structure is obvious at a glance. Parent elements get one child per line at the correct depth, elements that contain only text stay on a single line like <name>Ada</name>, and self-closing tags keep their compact form. You can pick 2-space or 4-space indentation. The XML declaration, DOCTYPE, comments and CDATA sections are recognised and kept intact, and CDATA content is preserved byte-for-byte because whitespace inside it can be meaningful.

Every keystroke also runs a strict validation pass with the browser's built-in DOMParser in application/xml mode. Well-formed input shows a green confirmation; malformed input surfaces the parser's own error message, including the line and column where the browser reports them. That makes the tool double as a quick XML validator for tracking down unclosed tags, unescaped ampersands and stray characters before a document reaches production.

Minify mode for smaller payloads

Switch to Minify and the same engine removes indentation and newlines between tags, trims text nodes and collapses whitespace runs, producing the smallest well-formed equivalent of your document. The live size readout shows input bytes, output bytes and the percentage saved. Minified XML travels faster in API payloads, RSS feeds and SAML or SOAP messages where every kilobyte counts, while comments and CDATA stay in place.

How to format XML online

Paste XML into the input box, click Load example to see a sample catalog document, or upload a .xml file (it is read locally, never sent anywhere). Choose Beautify or Minify, pick an indent width, and the output updates instantly with validation status and byte counts. Then copy the result or download it as an .xml file. Because the tool is one static page of JavaScript, it handles large documents without a server and keeps working offline after the page loads.

Frequently asked questions

What does an XML formatter do?

An XML formatter (or XML beautifier) takes a document that is cramped onto one line or inconsistently indented and rewrites it so every element sits at a depth matching its nesting. Elements that contain only text stay on a single line, while parent elements get one child per line. Tags, attributes, text content, comments and CDATA sections all stay intact; only the layout of the source changes.

How does the XML validation work?

Every time the input changes, the document is parsed with the browser's built-in DOMParser in strict application/xml mode. Well-formed documents show a green confirmation badge. Malformed documents surface the parser's own error message, including the line and column numbers where the browser provides them, so you can jump straight to an unclosed tag or a stray character.

What is the difference between beautify and minify?

Beautify adds indentation and line breaks to make XML readable for humans, with a choice of 2 or 4 spaces per level. Minify does the opposite: it removes whitespace between tags and trims text nodes to make the document as small as possible for transmission or storage. Use beautify while editing and minify when shipping data.

Can it handle comments, CDATA and processing instructions?

Yes. The XML declaration and other processing instructions, DOCTYPE declarations, comments and CDATA sections are all recognised as distinct tokens and kept intact in both modes. CDATA content is preserved byte-for-byte, since whitespace inside it can be meaningful, and comments are kept because stripping them could remove documentation.

Is my XML uploaded anywhere?

No. All formatting, validation and minification runs locally in your browser with plain JavaScript. Your XML never leaves your device, there is no server round-trip, and the page keeps working if you disconnect from the internet after it loads.

Related tools