XML Formatter

Pretty-print or minify XML with configurable indentation.

The XML Formatter pretty-prints XML with consistent indentation or minifies it onto a single line. It checks that the document is well-formed while it works and reports the line and column of the first problem. Use it to read minified API responses, tidy config files, or shrink XML before embedding it.

What is XML formatting?

XML is a text format built from nested elements, attributes and text. Whitespace between elements is normally insignificant, so the same document can be written on one line or spread over many indented lines without changing its meaning. Formatting (pretty-printing) adds line breaks and indentation so the nesting is visible; minifying removes that whitespace to make the document smaller. To do either safely the tool must first parse the document, which also proves it is well-formed: every start tag has a matching end tag, tags nest properly, attribute values are quoted and there is a single root element. Whitespace inside text content is trimmed when formatting, so formatting is for reading and tidying, not for documents where leading or trailing spaces in text matter.

How to use XML Formatter

  1. Paste your XML Paste the document into the XML box on the left. The result appears in the Result box as soon as the input parses.
  2. Pick an operation Choose Format to pretty-print or Minify to strip the whitespace between elements.
  3. Set the indent With Format selected, choose 2 spaces, 4 spaces or Tab in the Indent option.
  4. Copy or download Use the Copy button to put the result on the clipboard, or Download to save it as formatted.xml.

Frequently asked questions

Does formatting change my data?

It changes only whitespace between elements and trims leading and trailing whitespace inside text nodes. Element names, attributes, comments, CDATA sections and text values are kept. If your document depends on exact whitespace inside text, keep the original.

What is the difference between Format and Minify?

Format puts each element on its own line with the chosen indentation. Minify removes the whitespace between elements so the document is as compact as possible.

Why is my document with a DOCTYPE rejected?

DOCTYPE and entity declarations can be used to define entities that expand into very large or external content. The tool rejects them rather than processing them. Remove the declaration to format the rest of the document.

Can I choose tabs instead of spaces?

Yes. Set Indent to Tab and each nesting level is indented with one tab character.

Is my XML sent anywhere?

No. The document is parsed and formatted in the page, and the input is not sent to a server.

Does it validate against a schema?

No. It checks that the XML is well-formed, which means correctly structured. It does not check the document against an XSD or DTD.