LocalExcelTool
Get started

XML Formatter

Beautify XML/HTML with indentation matching the tag hierarchy.

Runs in your browserNo account neededFree

What is XML Formatter

XML formatting adds line breaks and indentation according to tag nesting, making the structure of XML or HTML easy to read.

🔒 Everything runs in your browser. Nothing is uploaded.

What this tool actually does with your file

Where it runs
In your browser, on this page
Upload
None — the file never leaves your device
Offline
Works with the network disconnected

Whitespace between tags is not always insignificant

The formatter collapses runs of whitespace that sit between a closing angle bracket and an opening one, then re-indents by element depth. For machine-generated XML that is exactly right: the whitespace was inserted by an earlier pretty-printer and carries no meaning.

For hand-written XML it can be wrong. In mixed content — <p>hello <b>world</b> again</p> — the space before <b> is part of the text, and an aggressive pass can normalise two spaces to one or move text to its own line. The document still parses, but the rendered sentence changes.

Constructs that must be left alone

CDATA sections, xml:space="preserve" subtrees, and element content in XHTML must keep their internal whitespace exactly. A formatter that treats CDATA inner text as ordinary content will alter code samples or embedded scripts.

Attribute order is also worth noting: formatting should preserve it, because while XML says attribute order is insignificant, plenty of real systems diff attribute order and some signing schemes canonicalise it. Reordering attributes can invalidate an XML signature even though the document is logically identical.

Valid versus well-formed

This tool checks balance and structure, which is well-formedness. It cannot tell you whether the document matches a DTD or an XSD — that requires the schema, and it is the check that matters when an integration rejects a payload that looks perfect.

The common real-world failure is an unescaped ampersand in a URL query inside an attribute. & starts an entity reference, so ?a=1&b=2 is not well-formed; it must be written &amp;. Errors like that produce a parse failure pointing at a character that looks completely ordinary.

How to use it

  1. 1.Paste your XML
  2. 2.Click Format
  3. 3.Copy the result

How XML Formatter works under the hood

Formatters parse your input into a structure, then serialise it back with consistent indentation. That is why a formatter can also reveal a syntax error: if it cannot parse, it cannot print.

  1. 1

    Parse into a tree

    JSON goes through JSON.parse; YAML, XML, CSS and SQL use their own parsers. The parse either succeeds with a structure or fails at a line and column.

  2. 2

    Serialise with a fixed style

    Indentation width, key order and quoting are applied deterministically, so formatting the same input twice gives identical bytes.

  3. 3

    Show the error position

    When parsing fails, the message includes the position so the fix is obvious instead of guessed.

  4. Processing pipeline

Formatting is not validation

A formatter proves the document is syntactically parseable. It does not prove it is valid against a schema, and it does not check business rules. JSON with a duplicated key parses fine and silently keeps the last value.

What gets normalised

Comments are preserved in CSS and SQL but not in JSON, which has no comment syntax. YAML anchors may be expanded, and quote style may change. Keep the original when exact byte layout matters, such as signed payloads.

Verify it yourself

Formatting is deterministic and local — run it twice and compare.

  1. 1.Open DevTools on this page and switch to the Network tab
  2. 2.Keep the filter on Fetch/XHR and run the tool
  3. 3.Confirm no request carries your file — you should see only page assets and fonts

Frequently asked questions

What is XML formatting?

It indents tags by nesting level to clarify the structure.

Can I use it for HTML?

Yes, well-formed HTML can be formatted too.

What this kind of conversion cannot keep

Formatters parse the input into a tree and print it back with consistent indentation. If the input is invalid, you get the parser's error position instead of a silently mangled file — malformed JSON stays malformed rather than being «repaired» into something that is no longer yours.

More in Format