XML Formatter - Free Online XML Beautifier

XML Formatter

Format XML in your browser while preserving mixed content and significant whitespace.

This free XML formatter turns compressed or messy XML into clean, indented markup you can read and copy. Paste your XML, pick 2 spaces, 4 spaces or a tab, and the tool shows a formatted version, or a clear parse error if the XML is broken. It suits developers, testers and anyone debugging feeds or config files.

What Is XML and What Does Formatting Do?

XML (Extensible Markup Language) is a W3C text format for storing and exchanging structured data as nested tags. You meet it in sitemaps, RSS feeds, SVG images, Android layouts, SOAP messages, build and config files, and Office documents. Unlike HTML, XML has no fixed tag set: you define your own element names.

Formatting, also called beautifying or pretty printing, adds line breaks and indentation so the nesting is visible at a glance. A well-formed document needs one root element, properly nested tags, matching closing tags (names are case-sensitive), quoted attribute values and escaped special characters, such as & for an ampersand. Formatting does not repair these problems, but it makes them much easier to spot.

How to Use the XML Formatter

You can format a document in under a minute by following these steps.

  1. Open the Indentation menu and choose 2 Spaces (the default), 4 Spaces or Tab.
  2. Paste your markup into the Input XML box. The input can be up to 2 MB.
  3. Click Format / Beautify.
  4. Read the result in the Output panel. If a red XML Parse Error box appears instead, read its message, fix the input and try again.
  5. Click Copy to put the formatted XML on your clipboard.
  6. Click Clear to empty the box and start a new document.

If you click the button with nothing pasted, the tool asks you to paste some XML first.

Worked Example: From One Line to Readable Markup

Suppose you paste this single line: <root><item id="1"><name>Apple</name><price>1.20</price></item><item id="2"><name>Banana</name><price>0.50</price></item></root>

With 2 Spaces selected, the output puts <root> at the left edge. Each <item> sits two spaces in, and the <name> and <price> lines sit four spaces in, each with its text value on the same line. Both items now line up, so you can see in one glance that every item has a name and a price.

Switch to 4 Spaces or Tab and click the button again to get the same structure with wider steps. The meaning of the data never changes, only the whitespace between tags.

How Does the Formatter Treat Text, Comments and Mixed Content?

The formatter only adds line breaks where doing so cannot alter your data. An element that contains only other elements is split across lines and indented. An element that contains text stays on one line, so <name>Apple</name> is never broken apart.

This matters for mixed content, such as a paragraph with inline tags: <p>Hello <b>world</b></p>. Adding line breaks inside it would insert extra spaces into the text, so the tool leaves it intact. The same rule applies to these cases:

  • CDATA sections are kept exactly as written.
  • Elements marked with xml:space="preserve" are left untouched.
  • Comments and processing instructions are kept and placed on their own lines.
  • Empty elements stay compact.
  • An XML declaration at the top of your input stays on the first line.

What Does Serialize Safely Do?

Serialize Safely checks your XML and writes it back out without reflowing it, keeping text and comments exactly as they are. Use it when you want a parse check but must not change the layout. It is a cautious compact option, not an aggressive minifier, so whitespace that belongs to your document stays. If your input includes an XML declaration or a DOCTYPE, the tool returns it exactly as you pasted it.

How to Read the Results and Fix Parse Errors

A successful run fills the Output panel with indented XML and confirms that the XML was formatted. That also tells you the input is well-formed, because the tool cannot format a document it fails to parse. A failed run shows the first line of the parser message in the XML Parse Error box.

ProblemTypical causeFix
Mismatched tagClosing name differs from opening nameMatch spelling and capitalization
Unclosed elementA tag was never closedAdd the closing tag or self-close it
Bad characterRaw ampersand or less-than sign in textReplace with the escaped entity
Extra contentTwo root elements side by sideWrap everything in one root
Attribute errorUnquoted attribute valuePut the value in quotes

The reported message usually names a line and column. Go to that spot first, but remember the real mistake is often a few lines earlier, where a tag was opened and never closed.

Who Needs an XML Formatter?

Anyone who reads XML written for machines will benefit, because machine output is usually one long line. These are common situations:

  • Debugging API responses. A SOAP or REST reply pasted from a log becomes readable in one click.
  • Checking sitemaps and feeds. Paste a sitemap or RSS feed to confirm every entry is nested correctly. If you still need a sitemap, the XML sitemap generator can build one for you.
  • Cleaning config files. Android layouts, build files and settings files are easier to review in a diff when indentation is consistent.
  • Preparing data for conversion. Confirm the XML is well-formed first, then move it to JSON with the XML to JSON converter.
  • Quick edits without setup. Many people search for how to format XML in Notepad++, Visual Studio Code, Eclipse or IntelliJ. Those editors need a plugin or a settings change, while here you paste, click and copy.

Best Practices and Troubleshooting Tips

Pick one indentation style for your project

Two spaces keeps deeply nested files narrow, four spaces is easier to scan, and tabs let each reader set the width in their own editor. Match what your team or existing files already use, so version control diffs stay small.

Keep the XML declaration at the very start

If you include <?xml version="1.0" encoding="UTF-8"?>, it must be the first thing in the input. A blank line or space before it makes the XML invalid, and a common cause of a surprising parse error.

Escape special characters

Write &amp; for an ampersand and &lt; for a less-than sign in text. A single raw ampersand in a product name or URL query string is one of the most frequent reasons well-looking XML fails.

Do not paste HTML and expect the same result

HTML allows unclosed tags such as line breaks and unquoted attributes, which XML does not. For web pages, use the HTML formatter instead.

Check a long result before you replace the original

Copy the formatted version into a new file and compare it with the original. Only whitespace between tags should differ.

Limitations to Know About

This tool checks that XML is well-formed. It does not validate against an XSD or DTD, so it cannot tell you that a required element is missing or that a value has the wrong type. Documents that contain a DOCTYPE declaration are returned as you pasted them rather than reindented. Input is limited to 2 MB, so very large exports are better handled in a desktop editor.

For other languages, the code beautifier handles HTML, CSS and JavaScript, and the JSON formatter and validator covers JSON.

Paste your XML into the formatter above, choose an indentation style and click Format / Beautify to get readable, well-formed markup in seconds. You can find more utilities like it in the web developer tools collection.

Frequently Asked Questions

How do I format XML online?
Paste your XML into the Input XML box, choose 2 Spaces, 4 Spaces or Tab, and click Format / Beautify. The indented result appears in the Output panel. Click Copy to take it with you, or Clear to start over.
Does this XML formatter check if my XML is valid?
Yes, it checks that your XML is well-formed. Problems like mismatched tags or unquoted attributes show an XML Parse Error message. It does not validate against an XSD or DTD, so it cannot check element rules or data types.
Why does my XML show an XML Parse Error?
The XML breaks a well-formedness rule, such as an unclosed tag, a raw ampersand, two root elements or a space before the XML declaration. Read the message, go to the reported line and look a few lines earlier for the real cause.
Why are some elements kept on one line after formatting?
The formatter keeps elements that contain text on one line so it never adds spaces to your content. This protects mixed content, CDATA sections and elements marked xml:space preserve. Only elements that hold other elements are split and indented.
How can I format XML without a Notepad++ plugin?
Paste the XML into this formatter, pick your indentation and click Format / Beautify, then copy the output back into your editor. You need no plugin, extension or settings change, which helps when you work on a shared or locked-down machine.
Is the XML formatter free and is there a size limit?
Yes, the XML formatter is free and needs no sign-in. Input is limited to 2 MB, and anything larger shows a size message. For very large files, split the document or use a desktop XML editor.
Recommended

Explore VPN options

A VPN changes your network exit. It does not guarantee anonymity.

Hide Your IP Encryption Network coverage
Protect My IP Now

XML data preservation

Adds indentation only between element-only nodes. Mixed text, CDATA and xml:space content are preserved. Safe serialization retains significant whitespace and comments; DTD-bearing XML is returned unchanged. Input is limited to 2 MB.

Implementation reviewed: 4 October 2026. Source documentation