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
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
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
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
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", notid=1. - Escaped special characters: a bare
&or<in text must be written as&or<. 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
| Term | What it means here |
|---|---|
| Well-formed XML | XML that follows the core syntax rules: one root element, every tag closed and correctly nested, quoted attribute values, and escaped special characters |
| Valid XML | Well-formed XML that also matches a DTD or XSD schema; this tool checks well-formedness only, not schema validity |
| Root element | The single outermost element that wraps the rest of the document, such as <catalog> in the example above |
| Self-closing tag | An element with no content written as one tag, such as <tag/>; it does not add a nesting level |
| XML declaration | The 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-print | Reformatting markup with line breaks and indentation so its structure is easy to read, without changing the data |
| Minified XML | XML with the whitespace between tags removed, often all on one line, which is common in API responses and exports |
Frequently Asked Questions
Paste the XML into the input panel and click Format XML. If the document is well-formed, the formatted version appears in the output panel with one tag per line and two spaces of indentation per nesting level. Click Copy XML to copy it.
It checks that the XML is well-formed before formatting. The input is parsed with the browser’s built-in DOMParser, and if the parser reports an error, such as an unclosed tag or a missing root element, the tool shows an "Invalid XML" message instead of producing output.
No. Only well-formedness is checked: correct nesting, closed tags, quoted attributes, and similar syntax rules. The tool does not load or check a DTD or XSD schema, so a well-formed document can still be invalid for a particular schema.
The browser’s XML parser rejected the document. Common causes are an unclosed or mismatched tag, more than one root element, an unescaped & or < inside text (write & and <), an attribute value without quotes, or tag names that differ only by case, since XML is case-sensitive. The message does not point to the exact line, so check these in order.
No. The formatter always indents with two spaces per nesting level, and there is no setting to switch to four spaces or tabs.
No. Parsing and formatting both run in your browser with JavaScript, so the XML you paste, whether an API response, a SOAP payload, or an internal config file, is not sent to a server.
Element names, attributes, text values, and tag order are left as you typed them. What changes is the whitespace between tags: it is removed and replaced with line breaks and indentation. Whitespace-only text between tags, such as a single space inside an otherwise empty element, is removed as well.
No. This tool only pretty-prints XML. It removes whitespace between tags as part of reformatting, but the output is always the indented, multi-line version, not a compact one-line version.
Each is printed on its own line at the current depth. Unlike an opening tag, a self-closing tag such as <tag/>, an <?xml ...?> declaration, or a single-line comment does not add a level of indentation for the lines that follow.
Data-oriented XML, where each element holds either child elements or a text value, such as API responses, RSS feeds, sitemaps, and config files, formats cleanly. Document-style markup that mixes text and child elements inside one parent, as in XHTML paragraphs, may not indent consistently, and elements with one-character names such as <a> or <b> do not add an indentation level.
Yes. It is free to use with no signup, no install, and no usage limit.
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 & and <), attribute values without quotes, and tag names that differ only by case, since XML is case-sensitive.
