An XML formatter re-indents XML so that each element sits on its own line and nesting is easy to follow. Paste XML, choose an indent and the formatted document appears instantly; switch to Minify to strip the whitespace instead. The tool also checks that every tag is closed and correctly nested.
How to use the XML Formatter
- Paste your XMLPaste a document, a feed, a sitemap, an SVG or any XML fragment.
- Choose format or minifyPick the action and the indent width, and tick "Remove comments" if you want them stripped.
- Copy or downloadCopy the result or download it as an .xml file. If a tag is unclosed or mismatched, fix the line named in the error.
What the XML formatter does
XML produced by programs is often one long line. This XML formatter splits it into tokens (tags, text, comments, CDATA sections, processing instructions and the DOCTYPE) and prints them back with consistent indentation:
- Each element starts on its own line, indented one level deeper than its parent.
- An element that contains only short text stays on one line, such as
<price>44.95</price>. - Extra spaces and line breaks inside tags are collapsed, while attribute values are left untouched.
- Comments and CDATA sections are kept exactly as written unless you choose to remove comments.
Minify does the opposite: it removes the whitespace between tags so the file is as small as possible, without touching text that contains real content.
Formatting changes whitespace around text. For data-style XML such as feeds, sitemaps and configuration files this makes no difference. In documents with mixed content, where text and inline tags share a line and spaces matter, check the result. The xml:space="preserve" attribute is not honoured.
Checking that XML is well formed
Before formatting, the tool checks the basic rules every XML parser enforces. You get an error with the line and column when:
- a closing tag does not match the most recent opening tag (
<a><b></a>); - an element, comment or CDATA section is never closed;
- a tag name is not valid, which is usually a stray
<that should be written as<; - there is text outside the root element.
This is a well-formedness check, not full validation. It does not check attribute syntax in detail, resolve entities or validate against a DTD or XSD schema.
If the document has more than one top-level element, the tool still formats it and adds a warning, because a strict parser would reject it.
Your XML is processed in the browser and never uploaded. For web pages use the HTML formatter, which understands tags that XML would reject, and to create XML from data try the JSON to XML converter.
Frequently asked questions
How do I format XML online?
Paste it into the XML formatter and choose an indent of 2 spaces, 4 spaces or tabs. The indented XML appears immediately and can be copied or downloaded.
Does formatting change my XML data?
Tags, attributes and text stay the same. Only whitespace between tags and around text is changed, which does not matter for data formats such as RSS, sitemaps or config files.
Can it find errors in my XML?
It reports unclosed tags, mismatched closing tags, unclosed comments and invalid tag names, with the line and column. It does not validate against a schema.
Can I minify XML too?
Yes. Set the action to Minify to remove whitespace between tags, and tick "Remove comments" to drop comments as well. The size saved is shown.
Is my XML uploaded to a server?
No. Formatting happens in your browser and the content stays on your device.
Last updated 24 November 2026 by the TheTechFolk team.