How to use the XML Formatter
- Paste XML or open a file such as
.xml,.rss,.svgor.plist. - Choose 2 spaces, 4 spaces or tabs for indentation.
- If the XML is not well-formed, the error and line number are shown.
- Copy or download the formatted result.
What is an XML formatter?
An XML formatter (or pretty-printer) re-indents a document so every element starts on its own line and nesting is visible at a glance. It is the fastest way to read an API response, a minified feed, a generated sitemap or a configuration file that arrived as one long line.
<catalog><product id="KB-001"><name>Keyboard</name></product></catalog>
becomes
<catalog>
<product id="KB-001">
<name>Keyboard</name>
</product>
</catalog>
Well-formedness check
Before formatting, the document is parsed with the browser’s XML parser. Well-formed XML must follow a few strict rules — breaking any of them produces an error with the line number:
- Exactly one root element.
- Every start tag has a matching end tag, or is self-closing (
<br/>), and tags nest properly. - Attribute values are quoted, and no attribute appears twice on one element.
&and<in text are escaped as&and<(or placed in CDATA).- Element names are case-sensitive:
<Item>is not closed by</item>.
Validation against a schema (XSD, DTD) is a separate step that checks which elements are allowed; well-formedness is the prerequisite for it.
Formatting rules
Elements that contain only text stay on one line (<price>89.99</price>), empty elements are kept compact, and CDATA sections and processing instructions are preserved unchanged. Need the opposite? The XML minifier removes the indentation again. Working with JSON instead? Use the JSON formatter.
Tools that pair well with the XML Formatter
- HTML Formatter — Paste minified or messy markup and get clean, consistently indented HTML — including embedded <style> and <script> blocks.
- SVG Optimizer — Clean up SVGs exported from Figma, Illustrator, Inkscape or Sketch with SVGO — and check the before/after preview to make sure the icon still looks right.
- CSS Formatter — Turn a minified stylesheet into readable CSS with one property per line and properly nested @media blocks.
- JavaScript Formatter — Unminify and pretty-print JavaScript, JSON or JSX with your preferred indentation and brace style — or strip whitespace and comments with a verified minifier.