Skip to content

XML Indent Online: Format, Tidy or Minify XML

Paste XML that arrived on one line and get it back with one tag per line, indented by nesting depth. Tick one box to minify it again.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Formatted XML

<catalog>
  <book id="1">
    <title>Dune</title>
    <year>1965</year>
  </book>
</catalog>

Summary

Opening tags
4
Closing tags
4
Size
92 chars

Quick answers

How do I indent XML online?
Paste the XML, choose 2 or 4 spaces and the indented version appears with one tag per line. <catalog><book id="1"><title>Dune</title></book></catalog> becomes five lines, with <book> indented one level and <title> two levels.
Should XML be indented with 2 or 4 spaces?
Either is correct, because the XML specification sets no indentation rule. Two spaces keeps deeply nested documents such as SOAP messages narrower. Four spaces makes each level easier to see in shallow files. Follow whatever the rest of the project uses.
Does indentation matter in XML?
Not to an XML parser's view of the element structure, which comes from the tags alone. Indentation is for human readers. The line breaks and spaces do become whitespace text between elements, which most applications ignore but a few treat as significant.
What is the difference between pretty print and minify?
Pretty printing adds line breaks and indentation so the nesting is easy to read. Minifying removes the whitespace between tags so the document is as small as possible for sending or storing. The default sample is 75 characters minified and 92 characters indented with 2 spaces.
Can I indent SVG, RSS or a sitemap with an XML formatter?
Yes. They are all XML, so the same rule applies: one tag per line, indented by depth. Self-closing tags such as <circle cx="12" cy="12" r="10"/> stay on one line with their attributes.

What XML Formatter does

This XML indenter puts every tag on its own line and indents it by its depth in the tree, using 2 or 4 spaces per level. An element that holds only text, such as <title>Dune</title>, stays on a single line so lists of simple fields remain compact. The XML declaration, DOCTYPE and comments are kept, each on a line of their own. Tick Minify instead of format to go the other way and strip the whitespace between tags. It works on any XML-based text: RSS and Atom feeds, sitemaps, SOAP envelopes, SVG and config files. It re-indents by pattern and does not validate, so it will not report a document that is not well-formed.

XML indentation with 2 spaces and 4 spaces

Input: <catalog><book id="1"><title>Dune</title><year>1965</year></book></catalog>. Each row is one line of the output and the number of spaces in front of it.

Output lineDepthLeading spaces at 2Leading spaces at 4
<catalog>000
<book id="1">124
<title>Dune</title>248
<year>1965</year>248
</book>124
</catalog>000

Total size is 92 characters with 2 spaces and 104 characters with 4 spaces. The tool reports 4 opening tags and 4 closing tags for both.

Indenting common XML documents

Each input was pasted as a single line and formatted with 2 spaces.

RSS feed

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>News</title><item><title>First post</title><link>https://example.com/1</link></item></channel></rss>

10 lines. The declaration and <rss> sit at depth 0, <channel> at 1, the channel <title> and <item> at 2, and the item's <title> and <link> at 3. Opening tags 6, Closing tags 6, Size 210 chars.

XML sitemap

<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/</loc><lastmod>2026-01-15</lastmod></url></urlset>

7 lines. <url> is indented 2 spaces and <loc> and <lastmod> 4 spaces. Opening tags 4, Closing tags 4, Size 196 chars.

SOAP envelope with a namespace prefix

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetPrice><Item>Apples</Item></GetPrice></soap:Body></soap:Envelope>

7 lines, with <Item>Apples</Item> at depth 3. Size 173 chars with 2 spaces and 191 chars with 4 spaces.

Prefixes and xmlns attributes are left exactly as written.

SVG icon

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g fill="none"><circle cx="12" cy="12" r="10"/><path d="M8 12h8"/></g></svg>

6 lines: <svg>, <g> at depth 1, <circle/> and <path/> at depth 2, then the two closing tags. Opening tags 2, Closing tags 2, Size 153 chars.

Self-closing tags are not included in either count.

Minifying an indented file

<catalog>, <book id="1">, <title>Dune</title>, </book> and </catalog> on five indented lines, with Minify instead of format ticked

<catalog><book id="1"><title>Dune</title></book></catalog> on one line. Size 58 chars.

What the formatter changes, and where to check the result

The tool splits the text at tag boundaries. That is fast and predictable, but it is not a full XML parser.

  • Whitespace between tags is replaced by the new line breaks and indentation.
  • Spaces at the start and end of an element's text are trimmed: <name> padded </name> comes out as <name>padded</name>. If that padding matters to your application, do not reformat that document here.
  • Mixed content is broken up. <p>Hello <b>bold</b> world</p> becomes five lines, with Hello, <b>bold</b> and world each on their own line.
  • An empty pair such as <empty></empty> is written as an opening tag and a closing tag on two lines.
  • A > character inside an attribute value, a comment that contains tags, or a CDATA section that contains > is split in the wrong place. Review those sections after formatting.
  • Attributes always stay on the same line as their tag, in their original order and quoting.
  • Minify removes only the whitespace between a > and the next <. Comments and the text inside elements are kept.
  • Indentation is 2 or 4 spaces. Tabs are not offered.

What the opening and closing tag counts tell you

The Summary counts opening tags and closing tags separately. In a well-formed document made of ordinary elements the two numbers are equal, so a difference is a quick hint that something was not closed. The sample catalog with its </book> deleted reports 4 opening tags and 3 closing tags.

Treat the figures as a hint and not as validation. Self-closing tags, comments, the XML declaration and DOCTYPE are left out of both counts. An opening tag made of a single character with no attributes, such as <g> or <p>, is also not counted, so SVG and XHTML fragments can show fewer opening tags than closing tags even when they are correct. A closing tag with the wrong name, as in <item>x</itme>, still counts as one closing tag, so the totals match and the mistake passes unnoticed.

To check that a document is well-formed, open it in a browser or run it through an XML parser such as xmllint. To check it against a schema you need a validating parser and the XSD or DTD.

Other ways to indent or tidy XML

For files on disk, large documents or automated jobs, a parser-based tool is the better fit.

ToolCommand or actionNotes
xmllint (libxml2)xmllint --format file.xmlIndents with 2 spaces by default and reports documents that are not well-formed
XMLStarletxmlstarlet fo -s 4 file.xmlThe -s option sets the number of spaces per level
HTML Tidytidy -xml -i file.xmlThe -xml flag treats the input as XML, -i turns on indentation
Pythonpython3 -c "import sys, xml.dom.minidom as m; print(m.parse(sys.argv[1]).toprettyxml(indent=' '))" file.xmlUses the standard library, no install needed
Code editorsThe Format Document commandMost editors need an XML extension or plugin installed for this

Step by step

  1. 1

    Paste your markup into the XML box.

  2. 2

    Set Indent size to 2 spaces or 4 spaces.

  3. 3

    Leave Minify instead of format unticked to indent, or tick it to remove the whitespace between tags.

  4. 4

    Read the Formatted XML (or Minified XML) output and the Summary of Opening tags, Closing tags and Size.

  5. 5

    Copy the result or download it as document.xml.

Questions people ask

Does this tool validate my XML?
No. It only checks that the text contains at least one tag, then re-indents it. Mismatched or unclosed tags are not reported as errors. The opening and closing tag counts give a rough signal, and a parser is needed for a real well-formedness or schema check.
Will formatting change the data in my XML?
Tag names, attributes and the characters of your text are kept. Whitespace is what changes: the gaps between tags are rewritten, and leading or trailing spaces inside an element's text are trimmed. For data-style XML that is harmless. For documents with mixed text and inline tags, check the output.
Can I indent XML with tabs?
Not with this tool, which offers 2 or 4 spaces. If your project requires tabs, format with 4 spaces here and convert leading spaces to tabs in your editor, or use a command-line formatter that lets you set the indent string.
Why did my comment or CDATA section get split across lines?
The formatter treats every < ... > pair as a tag. A comment that contains tags, or a CDATA section or attribute value that contains a > character, is cut at that character. Restore that section from the original after formatting.
Is there a size limit?
There is no fixed limit, but everything runs in the browser tab, so very large files make the page slow. For documents of many megabytes, use a command-line formatter.
Is my XML uploaded to a server?
No. Formatting and minifying happen in your browser with JavaScript. The text you paste is not sent anywhere, which matters for SOAP payloads and config files that contain internal details.
How do I print XML so it is readable?
Indent it first, then copy the result into a text editor and print from there with a fixed-width font. You can also download the result as document.xml and open it in a browser, which shows XML as a collapsible tree.
Does it keep the XML declaration and DOCTYPE?
Yes. Lines such as <?xml version="1.0" encoding="UTF-8"?> and <!DOCTYPE note SYSTEM "note.dtd"> are kept unchanged at the top, each on its own line, and they do not add an indent level.

Looking for something else? Browse all developer tools or see every tool.