XML Formatter

Indent and validate XML with clear error locations.

  • Runs in your browser
  • Free, no sign-up
Output · formatted

    
Paste XML to startCtrl Enter format · Ctrl Shift M minify

About the XML Formatter

XML often arrives as one long line: an API response, a sitemap, an RSS feed, an SVG icon or a config file exported by another program. The XML Formatter puts every element on its own line and indents it to show how the elements nest, with tag names, attribute values, comments and CDATA in different colors.

Every input is checked with your browser's own XML parser. If the XML is not well-formed, for example because a tag is never closed or an ampersand is not escaped, the status line tells you the line and column where the problem was found.

Minify does the opposite and removes the line breaks and indentation between tags, which makes files smaller for sending and storing. You can also remove comments in either mode. Everything runs in your browser, so your XML never leaves your device.

How to use it

  1. Add your XMLPaste it into the Input box, drop a file onto it, or use Open file. XML, SVG, RSS, Atom, XSD, XSL, plist and .config files all work. Sample loads a small book catalog.
  2. Choose Format or MinifyFormat spreads the XML over indented lines. Minify puts it back on one line without the whitespace between tags.
  3. Pick an indentChoose 2 spaces, 4 spaces or tabs for formatted output.
  4. Remove comments if you likeTurn on Remove comments to drop every <!-- ... --> comment from the output.
  5. Copy or downloadCopy the result, or download it as formatted.xml or minified.xml.

Key features

Validation built in

Each change is checked by the XML parser in your browser. "Valid XML" plus the number of elements means the document is well-formed.

Short elements stay on one line

An element that holds only text, like <title>The Long Way Home</title>, stays on one line instead of being split into three.

Everything kept

The XML declaration, DOCTYPE, comments, CDATA sections, entities like &amp; and attribute quotes are copied exactly.

Indent and minify

2 spaces, 4 spaces or tabs for reading, or one compact line for sending.

Syntax colors

Tag names, attribute values, comments, declarations and CDATA each have their own color, so the structure is easy to scan.

Private by design

Your XML is formatted in your browser. Nothing is uploaded or stored.

Examples

Formatting a catalog

The Sample button loads a 422-byte catalog on a single line. Formatted with 2 spaces, it becomes 22 lines, and the status line reads Valid XML with 14 elements · 22 lines · 515 B:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <!-- spring list -->
  <book id="b1" lang="en">
    <title>The Long Way Home</title>
    <author>R. Patel</author>
    <price currency="USD">12.99</price>
    <tags>
      <tag>fiction</tag>
      <tag>travel</tag>
    </tags>
  </book>
  <book id="b2">
    <title>Cooking &amp; Lentils</title>
    ...

Notice that &amp; stays escaped and the CDATA section in the second book is kept as it is.

Indent size and file size

OptionLinesSize
Minify1422 B
Tabs22479 B
2 spaces22515 B
4 spaces22587 B
2 spaces, Remove comments21492 B

Tidying an SVG icon

This SVG, pasted on one line:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor"/><path d="M8 12l3 3 5-6"/></svg>

comes out as 4 lines and 3 elements:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor"/>
  <path d="M8 12l3 3 5-6"/>
</svg>

Errors the parser catches

You pasteThe problem
<a><b>text</a><b> is never closed
<Note></note>Tag names are case-sensitive
<a>Tom & Jerry</a>& must be written &amp;
<a id=1/>Attribute values need quotes
<a/><b/>Only one root element is allowed
<br>Empty tags must end with />

The exact wording of the message comes from your browser, so Chrome, Firefox and Safari phrase it differently. Each one gives the line and column.

Tips

  • Keyboard users can format with Ctrl Enter and minify with Ctrl Shift M; on a Mac, use Cmd instead of Ctrl.
  • Format a sitemap or RSS feed before you read it. Problems such as a missing <loc>, a stray tag or an unescaped & are much easier to spot on separate lines.
  • Minify SVG icons before you inline them in HTML or CSS, and turn on Remove comments to drop the notes that design programs often add.
  • When the formatter reports an error you cannot see, look just before the reported position. A tag that was never closed is often reported where the parent element ends.
  • If your XML has an encoding other than UTF-8 in its declaration, open it as a file in a text editor first and save it as UTF-8, then paste or open it here.

Common mistakes and limits

  • Formatting documents with mixed textIn XHTML, DocBook or similar files, text and tags are mixed, as in <p>Hello <b>world</b> again</p>. Formatting puts each piece on its own line and trims the spaces around the text, which changes the spacing when the text is displayed.
  • Expecting Minify to keep spaces between tagsMinify removes whitespace that sits between two tags. In <b>world</b> <i>again</i> the space between the elements is dropped. For data XML that is what you want; for mixed text it is not.
  • Treating HTML as XMLHTML allows <br>, unquoted attributes and unclosed <p> tags. XML does not, so most HTML pages fail here. Use the HTML Beautifier for HTML.
  • Confusing well-formed with validThis tool checks that the XML is well-formed: tags match, attributes are quoted and so on. It does not check the document against a schema (XSD) or a DTD.
  • Putting anything before the XML declarationThe <?xml ...?> line must come first. A comment or an element before it makes the XML invalid. This tool ignores blank lines at the start, but many other programs reject even those.

Frequently asked questions

What does an XML formatter do?
It adds line breaks and indentation so each element sits on its own line, nested under its parent. That makes long or machine-written XML easy to read and edit.
Does it check that my XML is valid?
It checks that the XML is well-formed, which is what every XML parser requires: matching tags, one root element, quoted attributes and escaped special characters. It does not check against a schema or DTD.
Can I format SVG, RSS and sitemaps?
Yes. They are all XML. Open or paste .svg, .rss, .atom, sitemap.xml, .xsd, .xsl, .plist and .config files the same way.
Are comments and CDATA kept?
Yes. Comments stay unless you turn on Remove comments, and CDATA sections are copied unchanged. Entities such as &amp; and &lt; also stay as they are.
What does Minify remove?
Line breaks and indentation between tags. Text inside elements and attribute values are not changed. Comments are removed only when Remove comments is on.
Why does my HTML fail?
HTML is more forgiving than XML. Tags like <br> or <img> without a closing slash, unquoted attributes and unclosed paragraphs are errors in XML.
Is there a size limit?
You can open files up to 10 MB. Inputs over 200,000 characters refresh a moment after you stop typing, and very long output is shown without syntax colors.
Is my XML uploaded?
No. Formatting and validation happen in your browser. Nothing is sent to a server.