XML Formatter
Pretty print XML online with proper indentation. Malformed XML is reported with its line and column, so you can find broken tags fast. Runs in your browser.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the XML Formatter
The XML Formatter pretty-prints XML with clean indentation while keeping mixed content (text with inline elements) on one line, so the meaning of your document does not change.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the XML Formatter
- Paste XML or open a file.
- Choose the indentation.
- Fix any error at the reported line and column, then copy or download the result.
Example
Input
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetPriceResponse><Price currency="EUR">19.99</Price><InStock>true</InStock></GetPriceResponse></soap:Body></soap:Envelope>
Result
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetPriceResponse>
<Price currency="EUR">19.99</Price>
<InStock>true</InStock>
</GetPriceResponse>
</soap:Body>
</soap:Envelope>The declaration stays at the top, each element is indented by nesting level, and elements that only contain text stay on one line.
Common mistakes
- An unescaped & in text. A bare & (as in "Tom & Jerry") is a syntax error in XML. Write it as &, or wrap the text in a CDATA section.
- Mismatched tag case. XML is case-sensitive, so <Item> must be closed with </Item>, not </item>. The error points to the closing tag that does not match.
- Content before the declaration. Nothing, not even a blank line or a byte order mark, may come before <?xml ...?>. Remove it if the error mentions the declaration.
Works well with the XML Formatter
- XML Validator: check that a document is well-formed without changing it.
- XML to JSON: turn the XML into JSON for JavaScript code.
- XML Minifier: compress it again before sending it.
Frequently asked questions
Why is some content kept on one line?
Inside elements that mix text and tags, whitespace is part of the content. Adding line breaks there would change the text, so it is left as written.
Is the XML declaration kept?
Yes, the <?xml ...?> declaration is preserved at the top of the output.
Are comments and CDATA kept?
Yes. Comments, CDATA sections and processing instructions are kept and indented with the surrounding elements.
Can it format HTML?
Only XHTML, which is valid XML. For regular HTML, with void elements such as <br> and unquoted attributes, use the HTML Formatter.
Related tools
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.