XML Formatter & Beautifier

Paste minified or messy XML and get it indented or minified. It runs in your browser, and only the whitespace between tags changes.

Ctrl+Enter also works. Your XML is processed in your browser and never sent to a server.

A Formatter That Leaves Your Text Alone

The simple way to pretty print XML is to put every tag and every piece of text on its own line, indented by depth. That is harmless between child elements, and it breaks any element that mixes text and tags. Run this paragraph through it:

You wrote

<p>Hello <b>world</b>, again!</p>

Every tag and every piece of text on its own line

<p>
  Hello
  <b>world</b>
  , again!
</p>

The text of that paragraph is now “Hello”, a line break, “world”, another line break and “, again!”. An RSS reader, an XSLT stylesheet or a translation tool sees exactly that. This formatter indents an element only when its children are all elements. As soon as text appears among them, the element is copied as written, and the result tells you how many were.

What Is Never Touched

Kept as writtenExampleWhy
Text mixed with tags<p>Hello <b>world</b>!</p>A line break before <b> would become part of the sentence. The element is copied as written.
An element holding only whitespace<code> </code>Those two spaces are its content. They stay.
xml:space="preserve"<pre xml:space="preserve"> <b/> </pre>The document asks for its whitespace to be kept, so the whole element is left alone.
CDATA sections<![CDATA[ a < b ]]>Character data, copied byte for byte, and the element around it is not re-indented.
Attribute values and quotestitle='a > b'Single or double quotes, line breaks inside a value, entities: all kept. Attribute order is never changed.
Comments, processing instructions, the DOCTYPE<!DOCTYPE note [<!ENTITY gt2 ">">]>Copied verbatim, internal subset included. Comments go only if you tick Remove comments.

What does change is whitespace and nothing else: indentation between child elements, the spacing inside tags (one space between attributes, none around = or before />), and Windows line endings, which become LF exactly as an XML parser reads them. Delete every space, tab and line break from the input and from the output, and you get the same text.

What You Can Do With It

Read a sitemap or a feed

Sitemaps and RSS feeds are usually served on one line. Paste one in and read it as a tree of <url> or <item> entries. Your own sitemap is at /sitemap.xml.

Tidy a config file

Maven pom.xml, Android manifests, .csproj files and Spring configs: re-indent with 2 spaces, 4 spaces or tabs to match the rest of the repository.

Inspect an SVG or a SOAP response

Exported SVG and API responses arrive minified. Format them to find the element you need, then minify again before shipping.

Find the broken tag

Invalid XML is not formatted. You get the line and column of the first error, a click that selects it, and the guide that explains the fix.

Formatting or Validating?

Both tools refuse XML that is not well-formed, and they use the same check, so they never disagree. This page is for shaping a document: indentation, minifying and comments. If you only need to know whether a file parses and where it breaks, the XML Validator is the shorter path. When either one finds an error, the XML error guides show the wrong and right version side by side, from unclosed tags to unescaped characters. For JSON, the JSON formatter makes the same promise: only whitespace changes.

Frequently Asked Questions

Does formatting change my XML?
Only whitespace changes, and only between tags in element-only content: the indentation between a parent and its child elements. Text, attribute values, quotes, entity references, comments, CDATA, processing instructions and the DOCTYPE are copied character for character. An element that holds text among its children is copied exactly as written, because adding a line break there would change the text.
Is whitespace between tags really safe to change?
Strictly, XML keeps whitespace between elements as text, and only a schema or DTD can declare it insignificant. In practice every consumer of sitemaps, feeds, configuration files and SVG ignores indentation between child elements, and that is the only whitespace this formatter adds or removes. Where text appears, or where the document uses xml:space="preserve", nothing is touched.
Is my XML sent to a server?
No. Formatting runs in your browser with JavaScript. The XML you paste is not uploaded, logged or stored, which makes the tool safe for SOAP responses, configuration files with credentials and customer data.
What is the difference between beautify and minify?
Beautify puts each child element on its own line, indented by depth, so the structure is readable. Minify removes the indentation between tags so the file is as small as possible. Text content is identical in both, and both describe the same document.
Why will my XML not format?
Only well-formed XML can be formatted. The formatter runs the same check as the XML Validator and tells you the line and column of the first error, with a link to the guide for it. The usual causes are a tag that is never closed, tags closed in the wrong order, an unescaped & or <, an attribute without quotes, or more than one root element.
Does it check my XML against a schema (XSD) or DTD?
No. It checks well-formedness, the rules every XML document must follow, not whether the document matches a particular schema. To validate against an XSD, use a schema-aware tool such as xmllint --schema schema.xsd file.xml.
Does it change <a></a> into <a/>?
No. Both forms mean the same thing, and the formatter keeps the one you wrote. It does tidy the inside of tags: the space between attributes becomes a single space, and spaces around = or before /> are removed.
What happens to line endings and the byte-order mark?
Windows line endings (CRLF) become LF, which is exactly what every XML parser does when it reads the file. A byte-order mark at the start is removed, and the result says so. The XML declaration, including its encoding, is kept as written.
Is there a size limit?
No fixed limit, since nothing is uploaded. A 5 MB sitemap formats in well under a second on a normal laptop. Nesting deeper than 1,000 elements is refused with an explanation rather than risking the browser tab.

Related Tools