XML Formatter & Minifier

Pretty-print or minify XML right in your browser — nothing is uploaded.

Free online XML formatter. Pretty-print messy XML with 2-space, 4-space or tab indentation, or minify it to a single line. Privacy-first — your XML never leaves your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

Is my XML uploaded anywhere?

No. The formatter runs entirely in your browser using JavaScript. Your XML is never sent to a server, which is why it works offline once the page has loaded.

XML formatter and minifier

Paste raw or minified XML and get back a clean, indented document — or collapse a formatted file back down to a single line. This is the everyday “beautify my XML” tool for developers working with SOAP envelopes, RSS/Atom feeds, Android layout files, SVG markup, sitemaps and config files that arrive as one unreadable line.

Pretty-print and minify rules

The formatter is a dependency-free pretty-printer that runs in two passes. First it tokenizes the input on tag boundaries, classifying each chunk as an opening tag, a closing tag, a self-closing tag (<x/>), a leaf (the <?xml ?> declaration, <!-- comments -->, CDATA or processing instructions) or a text node. Then it re-emits each token with indentation driven by a depth counter:

  • a closing tag dedents before it prints;
  • an opening tag prints, then indents its children;
  • self-closing tags and leaf tokens print on their own line without changing depth;
  • text sitting between an opening tag and its matching close is printed inline.

Minify mode skips the indentation entirely and joins every tag onto one line. Only whitespace between tags is touched — attribute values, text content, comments and CDATA are never altered.

Example

Paste this one-line input:

<note><to>Gera</to><body private="true">Hi</body></note>

With 2-space indentation, Format produces:

<note>
  <to>Gera</to>
  <body private="true">Hi</body>
</note>

Run Minify on the indented version and you get the original single line back.

Indent optionUse when
2 spacesDefault for most XML, SOAP and config files
4 spacesDeeply nested docs where extra width aids scanning
TabTeams that already indent with tabs

Everything runs locally in your browser as plain JavaScript — your XML is never uploaded, so it is safe for proprietary payloads and works offline once loaded.

When formatting vs minifying is the right move

Format for readability when you need to:

  • Debug a SOAP response from a legacy API by finding the right element
  • Review an Android layout XML file to understand view hierarchy
  • Read through a sitemap to check URL paths and modification dates
  • Inspect an RSS or Atom feed that an API returned as one unbroken string
  • Compare two XML config files visually (line-by-line diff works far better on formatted XML)

Minify for transport or storage when:

  • Sending XML over a network where payload size affects speed or cost
  • Storing XML in a database column where space is constrained
  • Embedding XML in a file format that expects a compact representation
  • Preparing a response from a service that was originally hand-formatted with inconsistent spacing

What this formatter does not do

This is a pretty-printer, not a validator or schema checker. It corrects indentation and collapses whitespace between tags, but it will not:

  • Tell you whether your XML is schema-valid (matches an XSD or DTD)
  • Fix unclosed tags or mismatched tag names
  • Normalise attribute quoting (single vs double quotes remain as written)
  • Handle XML namespaces specially — namespaced tags are treated as opaque token strings

If you need structural validation, use the XML-to-JSON converter on this site: a parse error there (signalled by a parsererror element in the output) means your XML is not well-formed.

CDATA and processing instructions

<![CDATA[ ... ]]> sections are treated as single opaque tokens and printed on their own line. Their contents — which can include characters that would otherwise be reserved in XML — are preserved byte-for-byte. Similarly, processing instructions like <?xml-stylesheet type="text/xsl" href="style.xsl"?> are kept as single-line tokens that do not affect indentation depth.

Whitespace in XML is data — format with care

Unlike JSON, XML has no single canonical notion of insignificant whitespace: text nodes are content, and the W3C XML specification provides the xml:space="preserve" attribute precisely because some documents carry meaningful spacing. A formatter must therefore distinguish element-only content (safe to re-indent) from mixed content — elements interleaved with text, as in XHTML paragraphs — where inserting line breaks would change the data. This tool re-indents structural markup and leaves text content intact, which is the conservative behaviour; if a downstream system compares documents byte-for-byte or signs them (XML digital signatures), format a copy for reading and keep the original untouched, because even semantically harmless whitespace changes break signatures and checksums.

MDN’s XML introduction is a good practical companion to the specification for teams newer to XML.

A related workflow habit: when inspecting XML from an API or log, format a copy immediately and keep the raw original beside it. The formatted copy is for reading; the original is what you attach to bug reports and reprocess, since it is the bytes the system actually produced.