XML Formatter

Pretty-print, minify, and validate XML documents with clear, line-numbered error messages.

XML Formatter

Pretty-print, minify, and validate XML documents with clear, line-numbered error messages.

Paste any XML snippet to pretty-print it with clean 2-space indentation, compress it to a single line for transport, or validate that every tag is properly opened, nested, and closed. Invalid documents get a precise error naming the offending tag and line number.

How to use this calculator

  1. Paste your XML into the input box.
  2. Choose Pretty print to indent it, Minify to compress it, or Validate only to check it.
  3. Click Format.
  4. Read the output — or the exact tag and line number if the XML is invalid.
  5. Use Copy to grab the result for your editor or API client.

The formula

The input is tokenized into tags, text, comments, CDATA, and declarations; a stack validates that opens and closes nest correctly; pretty-printing then re-emits each token with two spaces of indentation per nesting level.

Worked example

Pasting <root><child attr="1">text</child><empty/></root> and choosing Pretty print produces a four-line document with <child> indented two spaces and <empty/> on its own line. Choosing Minify on indented XML collapses <root><child>text</child></root> to a single line.

Frequently Asked Questions

What does the XML validator check?

It checks that every opening tag has a matching closing tag, that tags nest in the correct order (no <a><b></a></b> overlaps), and that tag names are syntactically valid. When something is wrong, it tells you the exact tag and line number, e.g. which closing tag was expected. It does not validate against an XSD schema or DTD.

Will it handle XML declarations, comments, and CDATA?

Yes. Processing instructions like <?xml version="1.0"?>, comments, CDATA sections, and DOCTYPE declarations are recognized and passed through untouched, each placed on its own line in pretty-print mode. Attribute values are preserved exactly as written.

What are the limits of this formatter?

It is a best-effort formatter, not a full XML parser. Attribute values containing a > character can confuse the tokenizer, and it does not resolve namespaces or external entities. For schema validation or XSLT-scale documents, use a dedicated XML IDE or xmllint.

Is my XML sent to a server?

No. All formatting happens locally in your browser — your XML never leaves the page. That makes it safe for config files or API payloads you would rather not paste into a random server-side tool.

How is minify different from pretty print?

Pretty print expands the document across lines with two-space indentation per nesting level so humans can read it. Minify strips all insignificant whitespace between tags to produce the smallest single-line document, which is useful when embedding XML in URLs, JSON strings, or size-sensitive payloads.