Developer Tools

XML Formatter

This free XML Formatter checks that your XML is well-formed with the browser's built-in parser, then pretty-prints it with each tag on its own line and two spaces of indentation per nesting level. Everything runs in your browser, so nothing you paste is uploaded.

Runs in your browser. Your files and text never leave your device - nothing is uploaded.

Format and Pretty-Print XML Online

The Tools Kit's free XML Formatter turns minified, single-line, or messily indented XML into clean, readable markup. Paste a document, click Format XML, and every tag is placed on its own line with two spaces of indentation per nesting level, so the structure of an API response, RSS feed, sitemap, or config file is easy to follow at a glance.

Before it reformats anything, the tool checks that the XML is well-formed using your browser's built-in XML parser. Broken markup is rejected with an error message instead of being turned into output that looks right but is not. Everything runs in your browser, so the XML you paste is not uploaded anywhere.

How to Use the XML Formatter

  1. 1

    Paste your XML

    Paste or type XML into the XML Input panel. A short sample document is preloaded so you can try the formatter straight away.

  2. 2

    Click Format XML

    The browser’s built-in XML parser first checks that the document is well-formed. If it is not, an "Invalid XML" message appears and no output is produced.

  3. 3

    Review the indented output

    Valid XML appears in the Formatted XML panel with each tag on its own line, indented two spaces per nesting level.

  4. 4

    Copy the result

    Click Copy XML to put the formatted markup on your clipboard, ready to paste into an editor, ticket, or config file.

You do not need an account, and there is no limit on how often you format XML.

XML Beautifier Example: Before and After

Here is a minified XML document with a declaration, a comment, attributes, and a self-closing tag, all on one line:

<?xml version="1.0" encoding="UTF-8"?><catalog><!-- items --><book id="1"><title>XML</title><tags><tag/></tags></book></catalog>

After clicking Format XML, the output panel shows:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <!-- items -->
  <book id="1">
    <title>XML</title>
    <tags>
      <tag/>
    </tags>
  </book>
</catalog>

Each opening tag such as <catalog> or <book id="1"> adds one level of indentation for the lines below it, and its closing tag steps back out before it is printed. The <?xml ...?> declaration, the comment, and the self-closing <tag/> are printed at the current depth without adding a level. An element that holds only text, like <title>XML</title>, stays on a single line. Attribute values, text, and the order of elements are left exactly as they were.

XML Validator: Well-Formed vs. Valid XML

An XML document is well-formed when it follows the basic syntax rules that every XML parser enforces. It is valid when it is well-formed and also matches a specific DTD or XSD schema. This tool checks the first of these: it parses your input with the browser's DOMParser and stops if the parser reports an error. It does not load or check any schema.

The well-formedness rules most often broken are:

  • One root element: everything must sit inside a single outermost element.
  • Closed, properly nested tags: <a><b></a></b> is an error; the inner element must close first.
  • Case-sensitive names: <Item> cannot be closed by </item>.
  • Quoted attributes: write id="1", not id=1.
  • Escaped special characters: a bare & or < in text must be written as &amp; or &lt;. The HTML entity encoder escapes these characters for you.

The error message is general and does not name the line, so if your XML is rejected, work through the list above. To find what changed between a working and a broken version of a file, paste both into Text Compare to see the differences side by side.

What the Formatter Changes, and What It Does Not

The formatter works on whitespace between tags. Any spaces, tabs, or line breaks between a closing > and the next < are removed, then a fresh line break and indentation are added. That includes whitespace-only text, so an element containing just a space ends up empty. Text inside an element that holds a value is kept as typed.

Indentation is fixed at two spaces per level; there is no option for four spaces or tabs, and no minify mode. The formatter is designed for data-oriented XML, where each element contains either child elements or a text value. Document-style markup that mixes running text with child elements inside one parent, such as an XHTML paragraph with inline tags, may not indent consistently. Elements with a one-character name, such as <a> or <b>, are also not recognised as opening tags, so their children are not indented beneath them. For HTML, CSS, or JavaScript, use the Code Beautifier instead.

Common uses

  • Reading a minified XML or SOAP response from an API while debugging an integration
  • Checking that a hand-edited config, sitemap, or RSS feed is well-formed before deploying it
  • Tidying XML before pasting it into documentation, a code review, or a support ticket
  • Comparing two versions of an XML file after formatting both the same way
  • Inspecting XML before converting it to another format for a JavaScript app

If you need the data as JSON rather than XML, the XML to JSON converter handles that, and JSON to XML goes the other way. For JSON itself, the JSON Formatter does the same pretty-print and validation job, and the SQL Formatter tidies database queries. More tools like these are collected in Developer Tools.

XML formatting terms explained

TermWhat it means here
Well-formed XMLXML that follows the core syntax rules: one root element, every tag closed and correctly nested, quoted attribute values, and escaped special characters
Valid XMLWell-formed XML that also matches a DTD or XSD schema; this tool checks well-formedness only, not schema validity
Root elementThe single outermost element that wraps the rest of the document, such as <catalog> in the example above
Self-closing tagAn element with no content written as one tag, such as <tag/>; it does not add a nesting level
XML declarationThe optional <?xml version="1.0"?> line at the top of a document; it is printed at the current depth like a self-closing tag
Pretty-printReformatting markup with line breaks and indentation so its structure is easy to read, without changing the data
Minified XMLXML with the whitespace between tags removed, often all on one line, which is common in API responses and exports

Frequently Asked Questions

Reviewed by Raja Jahangir · Last reviewed: October 7, 2026

How do you format and validate XML?

To format XML, paste the document and click Format XML. The browser's XML parser first checks it is well-formed; an unclosed tag, for example, produces a general Invalid XML message and no output. Valid XML is reformatted with each tag on its own line, indented two spaces per level, while text-only elements stay on one line.

Why is my XML invalid?

The most common causes of invalid XML are an unclosed or mismatched tag, a missing single root element wrapping everything, an unescaped ampersand or less-than sign inside text (write &amp; and &lt;), attribute values without quotes, and tag names that differ only by case, since XML is case-sensitive.

Sources and standards