XML Formatter

Pretty-print XML with configurable indentation and well-formedness checks.

Developer Runs in your browser
XML
Formatted XML

Nothing formatted yet

Paste XML and press Format. Comments, CDATA sections and mixed text content are preserved exactly, so formatting cannot change what it means.

Runs entirely in your browser. Your data isn't uploaded — this page makes no network request with anything you type, which you can verify in your browser's network tab. How this works.

What is the XML Formatter?

XML that arrives minified — a SOAP response, an RSS feed, an OOXML fragment, a Maven pom.xml pasted from a log — is unreadable until something re-indents it. This formatter parses the document first, so formatting doubles as a well-formedness check: a mismatched or unclosed tag is reported by line and column instead of producing mangled or silently wrong output.

Elements that mix real text with markup, such as a sentence containing an inline <b> or <a> tag, are left exactly as they read rather than reflowed — reindenting them would insert whitespace a consumer could treat as meaningful, which is the one thing a formatter must never do to a document.

How to use it

  1. Paste your XML into the editor, or use Upload to load an .xml file.
  2. Choose an indentation style — 2 spaces, 4 spaces, or tabs.
  3. Choose whether empty elements self-close (<tag/>) or stay as a pair (<tag></tag>).
  4. Press Format (or Ctrl/Cmd + Enter). The result appears on the right.
  5. Use Copy to put the formatted XML on your clipboard, or Download to save it.

Example

A minified service config, formatted with 2-space indentation.

Input
<?xml version="1.0" encoding="UTF-8"?><service name="payments-api"><replicas>3</replicas><endpoints><endpoint path="/charge" method="POST"/><endpoint path="/refund" method="POST"/></endpoints></service>
Output
<?xml version="1.0" encoding="UTF-8"?>
<service name="payments-api">
  <replicas>3</replicas>
  <endpoints>
    <endpoint path="/charge" method="POST"/>
    <endpoint path="/refund" method="POST"/>
  </endpoints>
</service>

Features

  • 2-space, 4-space and tab indentation
  • Well-formedness checked while parsing, with exact line and column on error
  • Mismatched and unclosed tags reported by name and the line they were opened on
  • Comments, CDATA sections and processing instructions preserved exactly
  • Mixed text-and-markup content never reindented
  • Duplicate attributes on one element reported as an error, per the XML spec

Frequently asked questions

Is my XML uploaded to a server?
No. Parsing and formatting happen in your browser using a parser built for this tool. The page makes no network request with your input, which is why it is safe to paste real payloads, including ones with internal hostnames or configuration values.
Does this validate against a schema or DTD?
No — it checks well-formedness (every tag closes correctly, attributes are not duplicated, entities are valid), not validity against a specific XSD or DTD. Nothing here resolves an external DOCTYPE or fetches anything over the network.
Why did formatting leave part of my document on one line?
That is deliberate: an element containing both text and child tags (mixed content, common in document-style XML like DocBook or XHTML) is left exactly as it was, because inserting indentation whitespace into it would change what a consumer renders. Purely structural elements — the common case for config files, feeds and API payloads — are reindented freely.
Esc

Loading the catalog…