XML Beautifier
Pretty-print or minify XML in your browser with 2/4-space or tab indent; keeps comments, CDATA and processing instructions and reports parse errors.
Your inputs and files stay in your browser
Input XML
Paste XML or drop an .xml file here to indent it or compact it to one line.
In the editor, Tab indents. Press Esc, then Tab to move focus out.
On this page
Turn a one-line or messily indented XML document into a neatly indented tree, or minify it for transport. The browser's own XML parser reads the input, so malformed markup is reported with a line and column instead of being silently “fixed”.
Detailed Functionality
Format puts every element on its own line, indented with 2 spaces, 4 spaces or a tab; an element that contains only text stays on one line (<to>Ann</to>), and empty elements are written as <b/>. Compact mode (minify) removes the whitespace between tags. The XML declaration, comments, <![CDATA[…]]> sections, processing instructions such as <?xml-stylesheet …?> and the DOCTYPE are kept, and special characters are escaped again on output (&, <, ").
Parsing is strict XML, not HTML: an unclosed or mismatched tag, a missing quote or an undefined entity stops formatting with the parser's message, for example error on line 1 at column 11: Opening and ending tag mismatch in Chrome. The internal subset of a DOCTYPE (<!DOCTYPE x [ … ]>) is not kept, because the browser does not expose it.
Open a .xml file or drop it onto the editor, then copy the result or save it as formatted.xml. The editor highlights tags, attributes and comments, folds elements and stays fast on large files. The indent and compact settings are remembered in this browser; the XML itself is never stored or sent anywhere.
Practical Examples
Indent a one-line document: <note><to>Ann</to><from>Bob</from></note> with 2 spaces becomes four lines — <note>, <to>Ann</to>, <from>Bob</from>, </note>.
Keep comments and CDATA: in <?xml version="1.0"?><!-- cfg --><config><db host="localhost" port="5432"/><![CDATA[a<b]]></config> the declaration and the comment end up on their own lines, and <![CDATA[a<b]]> stays unchanged inside <config>.
Minify: with Compact mode, an indented <root> containing <a>1</a> and <b/> becomes <root><a>1</a><b/></root>.
Spot a broken tag: <a><b></a> is rejected with “Opening and ending tag mismatch: b line 1 and a”.
How to Use This Tool
Add the XML
Paste it into the Input XML editor, click Open to load a .xml file, or drop the file onto the editor.
Choose the output style
Select the Indent size (2 spaces, 4 spaces or Tab) or enable Compact mode (minify).
Format
Click Format or press Ctrl+Enter (Cmd+Enter on macOS). Parse errors appear above the editor.
Use the result
Click Copy, or Save to download the result as
formatted.xml.
Tips and Best Practices
- Changing the indent or Compact mode re-formats the current document immediately.
- Mixed content is split and trimmed:
<p>Hello <b>world</b>!</p>becomes separate lines forHello,<b>world</b>and!. Don't reformat documents where spaces inside text matter. - HTML habits break XML:
<br>without a slash or without a DTD are errors here. - Click the arrows next to the line numbers to fold elements; Ctrl/Cmd+F searches the whole document.
- In the editor Tab inserts indentation; press Esc, then Tab to move focus out.
- No upload: the document is processed in the page, which also works offline after the first visit.