XML Beautify — Online XML Formatter and Pretty-Printer

🔒 Runs in your browser — nothing is sent to a server

XML formatter that turns any compact, minified or hand-written XML into a clean, indented document. Paste a SOAP envelope, an RSS feed, an Android layout, an Excel `.xlsx` part or any blob of XML, and this XML beautifier validates the syntax with the browser's native `DOMParser`, then pretty-prints the tree with 2 or 4 spaces or tab indentation. The XML declaration, DOCTYPE, comments and `CDATA` sections are preserved verbatim; mixed-content elements and `xml:space="preserve"` blocks are left untouched. Everything runs 100% inside your browser; your input never leaves your device, nothing is uploaded, logged or sent to any server.

Two-pane view: input and output side by side
Copied!

When to use an XML beautifier

You reach for an XML beautifier any time a one-line XML payload arrives unreadable: debugging a SOAP fault, tracing a SAML assertion through a signed envelope, comparing two SVG fragments with `diff`, peeking inside an Office Open XML part, walking through an Android `AndroidManifest.xml` from a vendor APK, or reviewing the RSS feed your CMS just emitted. The pretty-printed form is what most readers and tools expect, and what `xmllint --format` and IntelliJ both produce. Running the format in a browser-local tool keeps the payload off remote servers — important when the XML carries tokens, signatures or PII.

How XML beautifying works under the hood

XML beautifying is a three-step pipeline. First the input is scanned for the XML declaration and the DOCTYPE — both live outside the document tree, so they are pulled aside before parsing. Second the remainder is fed through `new DOMParser().parseFromString(input, "text/xml")`; a `parsererror` element in the result triggers a clear error message with the offending line and column. Third a recursive tree walker re-emits every element with the chosen indentation, preserving CDATA contents verbatim, keeping comments unless asked to strip them, leaving mixed-content and `xml:space="preserve"` elements on a single line, and breaking long opening tags (>120 characters) onto multiple lines. The whole pipeline runs inside the browser, so a multi-megabyte document beautifies in milliseconds without leaving your tab.

Examples

Input
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="1"><title>Atlas</title><author>A. Reyes</author></book><book id="2"><title>Vesper</title><author>I. Park</author></book></catalog>
Output
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1">
    <title>Atlas</title>
    <author>A. Reyes</author>
  </book>
  <book id="2">
    <title>Vesper</title>
    <author>I. Park</author>
  </book>
</catalog>
XML beautifier — minified document with declaration
Input
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"></circle><line x1="2" y1="12" x2="22" y2="12"/></svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="10"/>
  <line x1="2" y1="12" x2="22" y2="12"/>
</svg>
Pretty print XML — namespaces and self-closing tags
Input
<?xml version="1.0"?><tool><name>xml beautify</name><role>format xml online</role><client>free-converter.online</client></tool>
Output
<?xml version="1.0"?>
<tool>
  <name>xml beautify</name>
  <role>format xml online</role>
  <client>free-converter.online</client>
</tool>
Format XML online — payload that names the tool itself
Input
<config><!-- production settings --><script><![CDATA[if (a < b) { x = 1; }]]></script></config>
Output
<config>
  <!-- production settings -->
  <script><![CDATA[if (a < b) { x = 1; }]]></script>
</config>
Beautify XML file — comment and CDATA section preserved

FAQ

How do I beautify an XML document?

Paste the compact or minified XML into the input above, pick an indent (2 spaces by default, 4 spaces or tab as alternatives) and click Beautify. The XML formatter parses your input through the browser's native `DOMParser`, walks the resulting document tree and re-emits every element with consistent indentation. Errors from `DOMParser` surface immediately with the offending line and column.

What is XML beautifying or pretty-printing?

XML beautifying — also called pretty-printing — reformats compact XML by adding line breaks and indentation so a human can scan the structure. The data is unchanged: every element, attribute, text node, comment and CDATA section stays exactly as it was; only the cosmetic whitespace around tags differs. Beautified XML parses back to the same DOM as the original.

Does the formatter preserve the XML declaration and DOCTYPE?

Yes. The `<?xml version="1.0" encoding="UTF-8"?>` declaration is detected on the first line of the input and re-emitted unchanged at the top of the output. Any `<!DOCTYPE …>` declaration is preserved on the next line. Both belong outside the document tree, so they are extracted before parsing and re-attached during serialisation.

How does this XML beautifier handle CDATA and comments?

`<![CDATA[…]]>` sections are preserved character-for-character — only the indent in front of the opening `<![CDATA[` is touched. Comments (`<!-- … -->`) are kept by default and indented to match their surroundings. Tick "Remove comments" to strip them entirely, which is useful before diffing two XML documents that disagree only in inline annotations.

What does this tool do with mixed content like <p>Hello <b>world</b>!</p>?

It leaves it alone. Mixed-content elements — those holding both significant text and child elements — are emitted on a single line because pulling them apart would change the rendered whitespace. Any element carrying `xml:space="preserve"` is treated the same way: indentation stops at the boundary and the inner content is serialised verbatim.

How are long attribute lists wrapped?

Short opening tags stay on one line. When an opening tag with all attributes would exceed 120 characters and the element has more than one attribute, the formatter pulls each attribute onto its own indented line and aligns the closing `>` underneath the tag name. Diff-friendly and readable for SVG / SOAP elements with a dozen attributes.

How is XML beautify different from XML minify?

XML beautify and XML minify are exact opposites. Beautify adds line breaks and indentation between tags so a human can read the document. Minify strips every byte of optional whitespace to produce the smallest valid XML for transport or storage. The DOM tree and the data are identical in both directions; only the whitespace around tags differs.

Is it safe to paste sensitive XML into this beautifier?

Yes — the XML beautifier runs entirely in your browser using the native `DOMParser` and a tree walker written in plain TypeScript. Your input and the formatted output stay on your machine; nothing is uploaded, logged or cached. Safe for SOAP envelopes containing tokens, SAML assertions, signed payloads and internal config files.

Glossary

XML (Extensible Markup Language)

XML is a text-based, tag-oriented format for representing structured data, defined by the W3C XML 1.0 spec. It powers SOAP and WS-* web services, RSS and Atom feeds, Office Open XML (`.docx`, `.xlsx`), Android layouts, SVG, configuration files and countless legacy enterprise systems. An XML beautifier reformats compact XML without changing the meaning of any element or attribute it contains.

XML formatter

An XML formatter is any tool or function that takes XML input and emits it as a string with controlled indentation and line breaks. Browser `DOMParser` plus a custom tree walker, IDE plugins like the IntelliJ XML formatter, command-line `xmllint --format` and editor packages such as Prettier all qualify. Browser-local formatters keep secrets in SOAP and SAML payloads off remote servers.

CDATA section

`<![CDATA[ … ]]>` is the XML escape hatch for embedding text that contains characters which would otherwise need to be escaped — `<`, `>`, `&`, JavaScript and SQL snippets, or arbitrary scripted content. A correct XML beautifier never reformats the contents of a CDATA section; it only places the opening `<![CDATA[` at the right indent level and leaves everything inside untouched.

XML declaration

The XML declaration is the optional first line of an XML document — `<?xml version="1.0" encoding="UTF-8"?>` — that pins the XML version and the character encoding. It is not part of the document tree, so a `DOMParser` does not surface it on `documentElement`. A pretty-printer extracts the declaration before parsing and re-emits it verbatim at the top of the output.

Mixed content

Mixed content is an XML element that holds both significant text and child elements — for example `<p>Hello <b>world</b>!</p>`. Whitespace between text and tags is part of the rendered output, so a beautifier must not insert line breaks inside mixed-content elements. The same rule applies to any element marked `xml:space="preserve"`: its inner content is left exactly as written.

Self-closing tag

A self-closing tag like `<br/>` is XML shorthand for an element with no children — equivalent to `<br></br>`. A normalising XML beautifier collapses empty `<br></br>` pairs into the shorter form by default, mirroring what most XML editors emit. The behaviour is toggleable: tick the option off if you want the verbose form preserved exactly.

Related tools