XML formatter and beautifier

Paste one-line or badly indented XML to read it easily and review its structure.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter xml text, indentation and keep comments.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

The document is parsed and written again: each element on its own line indented by depth, a text-only element kept on one line, an empty element written as <a/>. Whitespace-only gaps between tags are dropped, attributes and text stay as they are.

Example

Inputs: Indentation = 2 spaces, Keep comments = yes. Result: Formatted XML: <?xml version="1.0"?> <root> <!-- c --> <a x="1">t</a> <b/> <c> <d>1</d> </c> </root>; Lines: 9.

<?xml version="1.0"?><root><!-- c --><a x="1">t</a><b></b><c><d>1</d></c></root>
<?xml version="1.0"?>
<root>
  <!-- c -->
  <a x="1">t</a>
  <b/>
  <c>
    <d>1</d>
  </c>
</root>

Limits and caveats

  • In mixed content such as <p>Hi <b>Ahmed</b></p> spaces around text pieces are trimmed.
  • An empty element <a></a> is written as <a/>, which XML treats as the same.

Questions about this tool

Does formatting change my data?

Tag names, attributes and element text stay the same, only line breaks and indentation between tags are added.

Why do I see an error?

The document is not well-formed, for example an unclosed tag or an unescaped &, and the message gives the line and column to fix.

Are comments kept?

Yes by default. Untick keep comments to remove them from the output.