KKwikfig.

XML Formatter

Pretty-print XML with consistent indentation or minify it back down, with mismatched and unclosed tags reported by name instead of a silent failure. Runs entirely in your browser — your numbers never leave this device.

XML input
Output

How it works

Indent of an element = its nesting depth × the chosen spaces (2 by default) | An element holding only text stays on one line: <name>fig</name> | Well-formed means every opening tag is closed in last-in, first-out order, and there is exactly one root element

Paste XML and the formatter walks it tag by tag, tracking nesting depth as it goes: opening tags descend a level, closing tags climb back, and each line is indented by its depth. An element whose only content is text — <name>fig</name> — stays on one line, because splitting it across three would make real documents longer without making them clearer. Comments, the XML declaration, processing instructions and CDATA sections are carried through as they are. Minify runs the same walk and joins everything back with the inter-tag whitespace removed.

Because the walk maintains the stack of open tags, the formatter also checks well-formedness as it goes, and it reports problems by name: a closing tag that does not match the innermost open element is reported as the pair that clashed, with its line, and a document that ends with tags still open names the unclosed element. Be clear about the boundary of that check: well-formed is not the same as valid. This tool cannot know your schema, DTD or business rules, so it will happily format a well-formed invoice whose totals are wrong — structure is checked, meaning is yours.

The everyday traps are worth naming: XML is case-sensitive (<Name> and <name> are different elements), attribute values must be quoted, and a raw & or < inside text must be written as an entity — the HTML Entity tool covers those spellings. Everything runs in your browser; pasted documents are never uploaded.

Worked examples

Pretty-printing a flat document

Input
XML = <root><name>fig</name><value>42</value></root>
Working
root sits at depth 0 with no indent; name and value sit at depth 1 with two spaces. Both hold only text, so each stays on one line instead of splitting into three.
Result
<root> <name>fig</name> <value>42</value> </root>

Deeper nesting, deeper indent

Input
XML = <catalog><book><title>Deep Work</title><pages>304</pages></book></catalog>
Working
book descends to depth 1 (two spaces) and its children to depth 2 (four spaces). The nesting you would otherwise have to count brackets to see is visible at a glance.
Result
<catalog> <book> <title>Deep Work</title> <pages>304</pages> </book> </catalog>

A mismatched closing tag, named

Input
XML = <a><b></a></b>
Working
The walk opens a, then b — so the next closing tag must be </b>. Finding </a> instead, it stops and names both sides of the clash and the line it happened on, rather than guessing which tag you meant to close.
Result
Error: Mismatched tags — expected </b> but found </a> (line 1)

Frequently asked questions

What is the difference between well-formed and valid XML?

Well-formed means the syntax rules hold: tags nest properly, attributes are quoted, there is one root element — the rules this formatter checks while it works. Valid means the document also obeys a specific schema or DTD: the right elements, in the right order, with the right types. No generic formatter can check validity, because it does not know your schema — be wary of any tool that claims otherwise.

Why does my document fail with an unclosed tag?

Somewhere an opening tag never met its closing tag — the error names the element left open at the end of input, such as <a> in <a><b></b>. The usual causes are a self-closing tag typed as an opening one (<item> where <item/> was meant), a closing tag with a spelling or case difference (</Item> does not close <item>), or a document truncated in copying.

Does formatting change the document's meaning?

For most XML, no: whitespace between elements is presentation, and this formatter only re-indents element structure while keeping text-only elements on one line with their text untouched. The exception is documents where whitespace inside mixed content is significant (some publishing formats). If your format treats text spacing as content, minify a copy and compare before trusting it in production.

How does it handle comments, declarations and CDATA?

They pass through as structural lines at their nesting depth, unchanged: the <?xml …?> declaration, <!-- comments --> and <![CDATA[ … ]]> sections are carried verbatim. CDATA content is never re-indented or entity-encoded — leaving it byte-for-byte alone is the entire point of a CDATA section.

Can it format a document with namespaces?

Yes. A namespaced tag such as <x:item xmlns:x="urn:example"> is treated as one element whose name includes its prefix, and opening and closing tags match when their full prefixed names match. The formatter does not resolve namespace URIs or check that prefixes are declared — that is schema-layer checking again.

Is the XML I paste uploaded?

No. Formatting and checking run entirely in your browser — documents never leave your device and are not stored or tracked.

Related tools

More in Developer Tools · Browse all tools