Skip to main content
SiteIndex
DeveloperReady to use

XML Formatter

Pretty-print and validate XML with readable indentation, cleanup, and error feedback.

Guide

Interactive workspace

No account required
XML Formatter

Indentation applies to element-only content. Mixed text, CDATA, and xml:space="preserve" content are not re-indented. DOCTYPE is unsupported. Browser parser errors include location details when available. Everything runs in your browser — nothing is uploaded.

Input: 92 characters · 1 lines · 92 bytes

Shortcuts (in the input box): Ctrl+Shift+F format · Ctrl+Shift+M minify · Ctrl+Shift+V validate.

How to use it

  1. Paste one well-formed XML document with a single root element.
  2. Select Format XML; fix any parser error before copying.
  3. Review two-space indentation; inline mixed-text content remains unchanged.
What is XML Formatter?

Pretty-print and validate XML with readable indentation, cleanup, and error feedback.

How it works

The browser XML parser validates the document before two-space indentation is added to element-only content. Mixed text and CDATA are not re-indented, and xml:space preserve is respected. Declarations, comments, and processing instructions are retained. DOCTYPE is rejected; limits are 500,000 characters and 100 formatted element levels.

Example input and expected output

Input

<root><item>value</item></root>

Expected output

<root>
  <item>value</item>
</root>
Common uses
  • Inspect a nested XML API fixture with readable element-only indentation.
  • Validate matching XML tags while preserving CDATA and mixed content.
Limitations
  • DOCTYPE and external entities are unsupported; this is not DTD or XSD validation.
  • Mixed-content descendants are kept unchanged. Browser serialization can normalize quoting and empty-element syntax.
Frequently asked questions
Does the formatter indent nested XML?
Yes. Element-only content is indented with two spaces per level, with consistent results when formatting again.
Why is mixed text not re-indented?
Inserting whitespace around inline child elements can change the meaning of text. Mixed-content elements are left unchanged, including their descendants.
Are CDATA and xml:space preserved?
Yes. CDATA content is retained, and xml:space preserve prevents indentation changes unless a descendant explicitly resets it to default.
Can I format XML with a DOCTYPE?
No. Remove the DOCTYPE and use literal content. The formatter does not resolve external entities or validate against a DTD or schema.
How are XML errors shown?
Invalid input clears the result and shows the browser parser's error text, including line and column details when available. Browser serializers may normalize attribute quoting or empty-element syntax.

Related tools