Skip to content

Indent elements, keep text

Format XML

A long XML line is hard to read. This page indents elements by two spaces, or removes the indent. It does not try to repair a broken tag.

The formatter walks tags and text. Quotes inside a tag are respected, so a greater-than sign in an attribute does not end the tag. Comments and declarations stay on their own lines and do not change the depth. A truncated tag or an unclosed quote is rejected. The page does not resolve entities from the network and does not display the markup as HTML.

Formatting happens in this tab. The document is not uploaded.

This tool runs in your browser. Turn on JavaScript to use it.

One element, indented

The attribute stays on the opening tag. The text sits on its own line.

Compact
<root><item id="1">Hi</item></root>
Pretty
<root> <item id="1"> Hi </item> </root>

How to use it

  1. 1Paste XML.
  2. 2Pretty-print it or minify it.
  3. 3If a tag is broken, the page stops instead of guessing.

Good to know

  • Two-space indent.
  • It does not validate against a schema.
  • It does not fetch a DTD.

Questions

Will this fix mismatched tags?

No. It rejects markup it cannot tokenize. Matching open and close tags is left to you.

Are entities expanded?

No external entities are fetched. The text is copied as written.

Can I preview the HTML?

No. The result stays as source text.

Related tools

  • Format and check JSON

    JSON is a data format with strict commas, quotes, and no comments. This page parses what you paste and prints it again with an indent, or on one line.

  • HTML entity encode and decode

    Browsers treat < as the start of a tag. If the characters are meant to be seen, the HTML source needs &lt; instead. This page writes that source. It does not render it.

  • Convert JSON and YAML

    YAML is easier to scan than a one-line JSON object, and JSON is what most programs parse. This page converts between them for a plain subset.