XML Formatter Online
Beautify or minify XML instantly in your browser.
When an XML formatter is the right tool
XML often arrives as one long line from an API, or with mixed indentation from several editors. A formatter is for that moment. You paste the document, choose Beautify or Minify, and get a rewritten copy — 2- or 4-space indent, or a compact string with most of the extra whitespace removed. The output updates as you type.
This is a tag tokenizer, not a full XML parser. It will not tell you whether the document is well-formed, and it can stumble on CDATA. If you need to compare two versions, use XML Diff. If the markup is HTML, use the HTML Formatter instead.
Use cases
Reading a minified API envelope or a feed
A SOAP response or an RSS file on one line is hard to scan. Beautify puts each tag on its own indented line and leaves character data next to the opening tag, which is usually enough to find an element or an attribute. Load Sample pastes a short bookstore document if you want to try that first.
Producing a compact copy
Minify strips comments and collapses whitespace when you need a smaller paste for a log or a fixture. Check that significant spaces in text or attributes still look right before you ship the result.
Tidying a file before you compare it
Two dumps with different wrapping can be formatted here, then pasted into XML Diff. Because this rewrite is not a canonical tree dump, attribute order and CDATA will still matter.
How formatting works
Beautify and Minify run as you type. Empty input leaves the output empty. Indent 2 or 4 applies only in Beautify mode; the default is 2 spaces. You can copy the output when it is present. There is no setting for tabs, and attributes are not sorted or rewritten.
Beautify looks for < and >, classifies each tag as opening, closing, self-closing, or a <? / <! declaration, and indents accordingly. Text between tags is trimmed and joined to the opening tag. Minify removes comments, then collapses whitespace.
<book>
<title lang="en">The Great Gatsby</title>
</book>
<book>
<title lang="en">The Great Gatsby
</title>
</book>After Beautify, the title text sits on the same line as <title>, and the closing tag starts on the following line at the parent indent. That is the usual shape this page produces for a simple element.
What this tool does not do
It does not validate XML, resolve entities, sort attributes, or rewrite namespace prefixes. CDATA sections and comments that contain > can be split at the first greater-than sign. Nothing is sent to a server. Very large documents can make the tab feel slow. To turn the same data into JSON, use the XML to JSON converter.
How to use XML Formatter
- Paste your XML into the input pane. The output updates as you type.
- Choose Beautify to indent, or Minify to compact the text. In Beautify mode, pick 2- or 4-space indent.
- Copy the result when it looks right. Use Load Sample to try a short bookstore example, or Clear to start over.
Frequently asked questions
Does this page parse or validate XML?
No. Beautify and Minify are text rewrites, not a tree parse. There is no well-formedness check, no DTD or XSD validation, and malformed input is still rewritten as tags and text. If you need to know whether a document is valid, use a validator such as xmllint, then come back here only to tidy indentation.
How does Beautify indent the document?
It walks the text for < and >, treats each slice as a tag, and keeps a nest level. Closing tags move out one level. Self-closing tags (ending in />) and declarations that start with <? or <! stay at the current level. Text between tags is trimmed and appended to the opening tag on the same line; the closing tag usually starts on the next line.
What does Minify change?
It removes <!-- --> comments, collapses whitespace between tags, and reduces other runs of whitespace to a single space. That can also squeeze spaces inside a text node or an attribute value. The result is a more compact string, not a guaranteed smaller valid document.
Will CDATA, comments with a “>”, or processing instructions survive intact?
Not always. The beautifier stops a tag at the first > it sees, so a CDATA section that contains > can be split, and a comment or declaration that contains > can be cut short. If your file uses CDATA or complex comments, check the output before you trust it.
Is my XML sent to a server?
No. Formatting runs in your browser as you type. Closing the tab discards what you pasted. Do not paste documents that contain secrets if you would not be comfortable with them sitting in memory on this device.
Is there a file size limit?
There is no server-imposed limit, because nothing is uploaded. A few thousand lines is comfortable. A very large dump can make the tab feel slow; in that case, format a smaller excerpt or use a local tool.
How is this different from XML Diff?
This page tidies or compresses a single document. XML Diff compares two documents and can pretty-print them first with its own tag tokenizer. Use this page when you only have one file to indent; use XML Diff when you need to see what changed.
Related tools and guides
References
- W3C XML 1.0 defines elements, attributes, and well-formedness. This page does not implement that specification; it only rewrites tags and whitespace.
- xmllint is a better local companion when you need validity, CDATA, or namespace-aware formatting.