Format an XML Document Online
Paste a minified or messy XML document and get a clean indented tree. Well-formedness is checked and errors are reported by line, with CDATA, comments, and namespaces preserved. Minify back to one line when needed.
XML Formatter
LOCAL · Browser-OnlyFormat, validate, and beautify XML data with proper indentation
Quick Start
- 1Paste your XML into the input area
- 2Pick 2 spaces, 4 spaces, or tabs for indentation
- 3Format to beautify or minify to compress
- 4Review any validation errors and copy the output
What This Tool Does
Four actions share one editor. Format reindents the document, Minify strips it back to a single line, Validate parses without changing anything and reports whether the document is well formed, and To JSON produces a rough object view of the tree.
Every action parses the XML first, so a mismatched tag or a stray ampersand stops with the line and column instead of producing broken output. Well-formedness is what is being checked here; there is no schema or DTD validation.
A stats bar counts elements, attributes and nesting depth, and adds comment, text node and CDATA totals when the document contains them, alongside the byte size before and after. Indentation can be two, three, four or eight spaces or a tab, and comments can be kept or dropped.
Limits Worth Knowing
- Formatting trims whitespace inside text nodes, so a document where leading or trailing spaces inside an element carry meaning should be minified rather than formatted.
- Minify protects CDATA sections and, when comments are kept, comment bodies, so their contents are never collapsed.
- The element and attribute counts in the stats bar are quick approximations rather than a full document walk.
- Syntax coloring is dropped above roughly 5000 output lines and the stats bar is skipped for documents over two megabytes. Formatting itself still works in both cases.
- The JSON view is lossy by design: attributes become keys prefixed with an at sign, mixed text becomes a #text key, every value stays a string, and comments and the doctype are dropped.
Common Questions
Does it validate against my schema?
Can I open an SVG with it?
Why did formatting not clear my errors?
More Format Tools
All formatters →Format JavaScript Online
Beautify and reindent messy or minified JavaScript with consistent formatting. Free online JavaScript formatter that runs in your browser.
Format & Beautify JSON Online
Paste minified or messy JSON and format it with proper indentation. Free online JSON formatter with validation.
Format SQL Queries Online
Beautify and indent SQL queries for better readability. Free online SQL formatter supporting MySQL, PostgreSQL, and more.
Format & Beautify XML Online
Paste XML data and format it with proper indentation and syntax highlighting. Free online XML formatter and validator.
Format & Beautify CSS Online
Paste minified or messy CSS and format it with proper indentation. Free online CSS formatter and beautifier.
Format & Beautify Code Online
Format and beautify JavaScript, Python, PHP, Java, and C++ code. Free online code formatter with syntax highlighting.
Looking for FAQs and advanced options? Visit the full XML Formatter page →