Skip to content

XML Formatter and Beautifier

Turn one long line of XML into an indented tree you can read. The formatter also checks that the markup is well-formed and can minify it again for transport.

Drop XML or HTML here

Paste markup, upload an .xml or .html file, or drag and drop code here to format instantly.

.xml, .html and .svg files, read in your browser

Formatter Controls

Waiting for markup
Ready. Paste XML or HTML to begin.

Input & Formatted Output

No syntax issues Line 1, Col 1

Raw Input

Editable 0 chars
1
Ready for input Syntax not checked yet
No file loaded

Formatted Output

Syntax highlighted 0 chars
1
No formatted output yet 0 matches
Ready to download

Validation & Parser Notes

Run validation to see parser notes and syntax issues here.

Code Snapshot

Snapshot idle
Detected Mode—
Indent Unit2 spaces
Elements0
Attributes0
Comments0
Output Size0 B

Runs in your browser. Nothing you type, paste or open here is uploaded.

To format XML, paste it into the Raw Input box or upload an .xml file, then select Beautify Code. The XML formatter puts each tag on its own line and indents child elements by 2 spaces (or 4, or a tab). It also parses the markup and lists any well-formedness errors, with a line number, under Validation & Parser Notes.

How to format XML online

  1. Add the XML. Paste it into Raw Input, drop a file on the upload box, or choose Select Markup File. Load XML Sample loads a small book catalog to test with.
  2. Check the mode. Code Mode is Auto detect, which treats .xml and .svg files and anything starting with <?xml as XML. Pick XML to force it.
  3. Set the style. Choose Indentation, whether Attributes stay on the same line or go one per line, and how Empty Tags are written.
  4. Beautify and save. Select Beautify Code (or press Ctrl+Enter in the input) or Minify Code, then Copy Output or Download to save an .xml file.

What an XML formatter does to your file

An XML beautifier reads the markup tag by tag and writes it back with line breaks and indentation that follow the nesting. Tag names, attributes, comments, CDATA sections and the <?xml ?> declaration are copied as they are. Here is a one-line document:

<?xml version="1.0"?><note><to>Ana</to><from id="7" lang="en">Raj</from><body/></note>

After Beautify Code with the default settings:

<?xml version="1.0"?>
<note>
  <to>
    Ana
  </to>
  <from id="7" lang="en">
    Raj
  </from>
  <body/>
</note>

Text content goes on its own indented line, so <to>Ana</to> becomes three lines. Most XML readers trim that whitespace, but if your format treats spaces inside elements as data, keep the original file for production and use the formatted copy for reading.

Well-formed vs valid XML: what the check covers

When you beautify or select Validate, the page parses your input with the browser's built-in XML parser. That tests whether the document is well-formed under the W3C XML 1.0 rules. It does not test whether it's valid against a DTD or an XSD schema, which would need the schema file. The most common well-formedness errors:

RuleBreaks itFixed
One root element<a/><b/><root><a/><b/></root>
Every tag closed<p>text<p>text</p>
Correct nesting<b><i>x</b></i><b><i>x</i></b>
Quoted attributes<item id=7><item id="7">
Escaped ampersand<q>A & B</q><q>A &amp; B</q>

Tag names are case-sensitive, so <Item> can't be closed with </item>. In Chrome and Edge the parser note reads like "error on line 3 at column 9: Opening and ending tag mismatch", which points you straight at the problem.

XML pretty print settings explained

  • Attributes: One per line splits long start tags, which makes attribute changes easy to spot in a code review. The <from> tag above becomes:
    <from
      id="7"
      lang="en"
    >
  • Empty Tags converts between <body/> and <body></body>. Both mean the same thing in XML, so pick whichever your team's style uses.
  • Text Nodes: Smart formatting joins text that was split across lines into one line. Keep compact text leaves the text as it was, trimmed at both ends.
  • Search Output highlights every match of a tag, attribute or value in the formatted result.

The Code Snapshot panel counts elements, attributes and comments in the output. Code Mode also has an HTML option, but for full web pages the HTML formatter is the better fit.

How to minify XML, and what to watch for

Minify Code removes the whitespace between tags, collapses runs of spaces into one and drops line breaks. Comments and the XML declaration stay. Use it to shrink a SOAP body, a sitemap or an SVG before you embed it. Beautify keeps short text on the same line as its tags (<to>Ana</to>), so beautifying and then minifying gives back the same text. Where text and child elements share a parent (mixed content), the line breaks added between them become single spaces, so minify the original file when exact whitespace matters.

To see what changed between two versions of a feed or config, paste both formatted copies into the diff checker; one tag per line gives a much cleaner line diff. Working with an API that returns JSON instead? Use the JSON formatter. On the command line, xmllint --format file.xml from libxml2 does a similar job.

Frequently asked questions

Is this XML formatter free?

Yes. It's a free XML formatter with no sign-up and no usage cap. Large files are limited only by your browser's memory.

How do I pretty print XML?

Paste the XML into the input box and select Beautify Code. Each element goes on its own line, indented 2 spaces per level by default.

Does the formatter validate XML against an XSD schema?

No. It checks that the XML is well-formed (closed tags, correct nesting, one root, quoted attributes). Checking against a DTD or XSD needs a schema-aware validator.

What does "Opening and ending tag mismatch" mean?

A closing tag doesn't match the most recent open tag, either because of a typo, different letter case, or tags closed in the wrong order. The parser note gives the line where it noticed the problem.

Can I format SVG, RSS or sitemap files?

Yes. They're all XML. Upload the .svg or .xml file, or paste the markup, and Auto detect treats it as XML.

Is a self-closing tag the same as an empty pair of tags?

Yes, in XML <tag/> and <tag></tag> are both an empty element. The Empty Tags setting converts between the two styles.

Is my XML uploaded to a server?

No. Parsing, formatting and minifying all happen locally in your browser, so the XML never leaves your device.

Updated 11 October 2026Reviewed by the ToolzyLab teamHow we test our tools