100% local — your data never leaves your browser

XML Formatter — Read a One-Line Document

Indent XML while what it says stays put. An element mixing text and children keeps its line, because in XML those spaces are content.

Instant Private Zero cookies
Indentation

XML input

XML output

What this tool does

Element content gets indented; text content does not.

<library><book><title>Dune</title></book></library>

becomes

<library>
  <book>
    <title>Dune</title>
  </book>
</library>

The rule that matters

An element that mixes text and child elements is left on a single line, exactly as written.

<p>Hello <b>world</b> again</p>

That stays as it is. The reason is the difference between XML and HTML that catches the most people: HTML collapses whitespace, XML does not. A line break inserted between Hello and <b> is not presentation in XML — it is character data, and it stays in the document for whoever reads it next.

So a formatter that indents inside mixed content is not making the document prettier; it is editing the text. This one indents the element as a block and leaves its inside alone.

What counts as indentation

Only a text node that is entirely blank, that contains a line break, and that sits in an element holding no significant text of its own. Everything else is content.

A single space between two elements on the same line — <b>x</b> <i>y</i> — is kept. Nothing in the document says it is negligible, and keeping it costs one character.

xml:space="preserve" suspends all of it, for that element and everything under it.

The prolog comes back as you wrote it

The declaration, the DOCTYPE and any processing instruction are copied verbatim:

<?xml version="1.1" encoding="ISO-8859-1" standalone="yes"?>
<!DOCTYPE library SYSTEM "library.dtd">
<?xml-stylesheet href="style.xsl"?>

All three survive. Rewriting a declaration to version="1.0" encoding="UTF-8" — which is what many tools do — relabels the document, and relabelling changes how its bytes are read.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Why was my <p> element left on one line?
Because it mixes text and child elements. XML has no equivalent of HTML’s whitespace collapsing: a newline added between `Hello` and `<b>` becomes part of the text and stays there. The element is indented as a block, and its inside is left exactly as you wrote it.
Does formatting change my document?
No. Only whitespace that is pure indentation is rewritten — a blank text node containing a line break, in an element that holds no significant text. Everything else, including `xml:space="preserve"` regions, comes back character for character. Formatting then minifying gives the same document you started from.
My declaration says ISO-8859-1. Will it be rewritten?
No. The prolog — declaration, DOCTYPE, processing instructions — is copied verbatim. Relabelling an ISO-8859-1 document as UTF-8 would change how its bytes are read, so the version, the encoding and `standalone` are left as you declared them.

Related converters