Developer Tools · Formatters

XML formatter.

Paste XML to pretty-print it with the indent you choose. Attribute order, CDATA, comments and the XML declaration stay as written. If the XML is not well-formed you get the line and column of the first error.

Advertisement

Your XML

Result

Paste XML and press Format XML.

Advertisement

What the formatter changes

Formatting only changes white space between elements: each child element goes on its own line, indented by depth. Tags are copied character for character, so attribute order, quoting, CDATA sections, comments, processing instructions, the XML declaration and any DOCTYPE are unchanged. Elements that hold only text stay on one line.

Warning: white space can be data

In XML, white space inside an element can be meaningful. The XML 1.0 specification (section 2.10) says applications may treat it as significant and defines the xml:space="preserve" attribute to ask for that. So this tool leaves an element exactly as written when it mixes text with child elements (for example <p>Hi <b>there</b></p>) or is marked xml:space="preserve", and it lists those elements in the result. Even elsewhere, if your application reads the white space between elements, check the output before you rely on it.

Minify and limits

Minify is a secondary option: it removes white space between elements and removes comments, again leaving mixed content and preserved elements alone. The formatter runs only on well-formed input, checked with your browser's built-in XML parser (DOMParser). That is a well-formedness check, not validation against an XSD or DTD. Error wording and position can differ between Chrome, Firefox and Safari, and only the first error is reported. To check a document without reformatting it, use the XML validator.

Sources: W3C, Extensible Markup Language (XML) 1.0, section 2.1 (well-formed documents) and section 2.10 (white space handling); MDN, DOMParser. Everything runs in your browser. Nothing you paste is stored or sent.

How to format XML, step by step

Paste your XML into the XML document box, pick 2 spaces, 4 spaces or a tab from Indent, and press Format XML. The result panel shows the indented document with a Copy button and a button that moves the result back into the input box so you can keep editing. If you only need the opposite, press Minify. Nothing is sent anywhere; the page parses and prints the text in your browser.

Worked example: a two-book catalog

This input is one line of 204 characters, the shape you usually get from an API response or a log:

<?xml version="1.0"?><catalog><book id="b1"><title>XML Basics</title><price currency="CAD">29.99</price></book><book id="b2"><title>Advanced XML</title><price currency="CAD">44.50</price></book></catalog>

With a 2-space indent the formatter returns 238 characters on 11 lines. The extra 34 characters are the line breaks and indentation:

<?xml version="1.0"?>
<catalog>
  <book id="b1">
    <title>XML Basics</title>
    <price currency="CAD">29.99</price>
  </book>
  <book id="b2">
    <title>Advanced XML</title>
    <price currency="CAD">44.50</price>
  </book>
</catalog>

Pressing Minify on that formatted text gives back the original 204-character line exactly, because the only thing formatting added was white space between elements. Each <title> and <price> stays on one line with its text, since an element that holds only text is never split.

Beautify, pretty print, format: the same operation

People search for “xml beautifier”, “xml pretty print” and “xml formatter” and mean one thing: re-indenting a document so its tree structure is visible. It is not validation and it is not conversion. The document that comes out is the same document, laid out differently, and that is why attribute order, quoting and entity references are copied through untouched.

When the tool leaves an element alone

The input <p>Call <b>now</b> today</p> mixes text and a child element. Re-indenting it would insert white space between “Call” and <b>, which a reader of the document could see as an extra space. So the formatter prints the <p> element exactly as typed and lists it in a warning under the result (“mixed text and child elements”). The same happens to any element carrying xml:space="preserve". This is common in XHTML fragments, DocBook, and Office or SVG text runs.

Common mistakes that stop the formatter

The error shows the line and column of the first problem and an excerpt of the source. Only the first error is reported, so fix it and run again. Browsers word parse errors differently, so the text you see in Firefox may not match Chrome.

What this tool does not do

It does not check a document against an XSD schema or DTD, does not sort or canonicalize attributes, and does not convert XML to JSON (the XML validator linked below does that). It also cannot know whether your application treats white space between elements as data. If a downstream parser reads that white space, compare the output against the original before you commit it.

Where you meet XML in practice

Sitemap files follow an XML protocol with a UTF-8 encoding requirement and a limit of 50,000 URLs per file, so a formatted copy is the easiest way to read one. SOAP envelopes, RSS and Atom feeds, Maven pom.xml files, Android layouts and SVG images are all XML too. For SVG specifically, the SVG optimizer shrinks a file rather than spreading it out.

Sources

Each source below was opened and checked in October 2026 (retrieved 2026-10).

Advertisement

Frequently asked questions

What does an XML formatter do?

It takes XML that is on one line or badly indented and re-prints it with each child element on its own line, indented by depth. It changes only the white space between elements; tags, attributes, comments, CDATA sections and the XML declaration are copied through as written.

Does formatting change my XML data?

Not the data an application normally reads. The exception is white space that is itself meaningful. The XML 1.0 specification lets applications treat white space as significant and defines xml:space="preserve" to ask for that, so this tool leaves mixed-content elements and preserved elements exactly as typed and lists them.

Why do I get an error with a line and column?

Because the text is not well-formed XML: a tag is unclosed or mismatched, there is more than one root element, an attribute value is unquoted, or a special character such as & is not escaped. The position points at the first problem the browser parser found. Fix it and format again.

Is an XML beautifier the same as an XML validator?

No. A beautifier changes layout and only needs the document to be well-formed. A validator checks well-formedness and may also compare the document with a schema. This page does the first; it does not validate against an XSD or DTD.

How do I format XML with tabs or four spaces?

Choose Tab or 4 spaces in the Indent menu before pressing Format XML. The default is 2 spaces. The choice applies only to the output; your input is not modified.

Can I format XML from the command line?

Yes. The libxml2 tool xmllint has a --format option that reformats and reindents output, with two spaces by default. Its own documentation says the option has not worked reliably and is weakest without a DTD, so check the result on documents with mixed content.

Does it remove comments?

Formatting keeps comments. Minify removes them, and the result tells you when it did. Elements with mixed content or xml:space="preserve" are still left alone when minifying.

Is my XML uploaded or stored?

No. Parsing uses your browser's built-in XML parser and the formatting script runs on the page. Nothing you paste is sent to a server or kept after you close the tab.