XML Formatter
Paste XML or HTML and get it indented, or collapsed to one line. It is lexed by hand rather than run through the browser's parser, which means comments survive, & stays & rather than becoming &, CDATA is preserved, and HTML that a strict XML parser would refuse still formats.
Try an example loads a minified export with a comment, entities and a CDATA block in it.
Three reasons not to use the browser's own parser
DOMParser is built in and free, and using it would be the obvious implementation. All three reasons not to come up on real files.
- It discards comments unless you walk for them. A comment in an XML export is frequently the only record of where the file came from and when. Losing it in a formatter is not acceptable.
- It normalizes entities. Parse and re-serialize and
&comes back as&,écomes back asé. Both are technically equivalent XML and neither is the document you handed over. If that file is going into a diff or a system that compares checksums, you have changed it. - It refuses HTML. An unclosed
<br>, an unquoted attribute value, a<p>that never closes: all are things browsers render happily andDOMParserin XML mode rejects outright. Most of what people paste into an XML formatter is HTML.
So this walks the text, captures every construct whole, and changes only the whitespace between nodes. What comes out is what went in, laid out.
Worked example
In, all on one line:
<?xml version="1.0" encoding="UTF-8"?><!-- exported 2026-09-03 --><orders currency="GBP"><order id="A-1043"><customer vip="true">Ada Lovelace</customer><line sku="W-1" qty="2">Widget, blue</line><note><![CDATA[Leave with <neighbour> if out]]></note></order></orders>
Out:
<?xml version="1.0" encoding="UTF-8"?>
<!-- exported 2026-09-03 -->
<orders currency="GBP">
<order id="A-1043">
<customer vip="true">Ada Lovelace</customer>
<line sku="W-1" qty="2">Widget, blue</line>
<note><![CDATA[Leave with <neighbour> if out]]></note>
</order>
</orders>
The declaration and the comment are both still there. The CDATA block is untouched, angle brackets and all, which is the entire purpose of CDATA and which a re-serializing formatter would escape into <neighbour>. And an element whose only child is a short piece of text stays on one line, because <customer>Ada Lovelace</customer> spread over three lines is worse to read, not better.
Whitespace inside an element is left alone
Text content is never reflowed. In XML, whitespace inside an element can be significant, and nothing in the document tells you whether it is. A formatter that word-wraps a paragraph is guessing, and when it guesses wrong it changes data.
Runs of whitespace between nodes are replaced by the indentation, because that whitespace is layout by definition. And <pre>, <textarea>, <script> and <style> are copied verbatim start to finish, since re-indenting the inside of any of those visibly breaks the page.
One attribute per line
An element with eight attributes on one line is a line nobody reads and a line that produces a useless diff, because changing one attribute rewrites the whole row.
<input
type="email"
name="contact"
id="contact-field"
placeholder="you@example.com"
required
/>
It applies only to elements with two or more attributes, so a simple tag is not spread over three lines for no reason. Boolean attributes with no value, which are legal in HTML, keep their bare form.
Minify, and what it removes
Minify collapses whitespace between nodes and, optionally, drops comments. Entities are still untouched, and text content still keeps its meaning: a run of whitespace inside a text node becomes one space rather than none, because deleting it entirely would join two words together.
Turn Keep comments off to strip them as well. The comment option is separate from the mode, so you can also strip comments while pretty-printing, which is occasionally what a build step wants.
What this is not
It is not a validator. A well-formedness check needs a real parser, and this deliberately does not use one. A document with a mismatched closing tag still formats, with the indentation drifting in a way that usually makes the mismatch obvious.
It also does not check against a schema or a DTD. If you need the XML turned into data rather than laid out, XML to CSV and XML to JSON do that, and XML to Table shows it as a grid.
Frequently Asked Questions
Does it work on HTML?
Yes, and that is a design goal rather than an accident. Void elements such as <br> and <img> are recognized and not given invented closing tags, unquoted attribute values are tolerated, and the contents of <pre>, <script> and <style> are copied verbatim.
Are my entities changed?
No. & stays & and é stays é. A formatter built on the browser's parser normalizes both, which produces a document that is equivalent XML but is no longer byte-identical to yours.
Will it tell me if my XML is malformed?
Not directly, because it does not parse. What it does do is format the document anyway, and a mismatched or missing closing tag shows up as indentation that keeps drifting rightwards, which in practice points at the problem quickly.
Why is a short element still on one line?
Because an element whose only child is a single line of text reads better that way. <name>Ada</name> spread across three lines makes a document longer without making it clearer. Elements with element children are always broken out.
Does it handle a > inside an attribute value?
Yes. The lexer tracks quoting while it scans a tag, so <a title="x > y"> is read as one tag rather than being cut in half at the inner bracket. That case breaks a surprising number of regex-based formatters.
How large a file can I format?
Up to 100 MB dropped as a file, with no element limit under that. Pasting is bounded by your browser's textarea. There is no sign-up and no daily quota on either.
Does anything I paste leave my computer?
No. There is no upload endpoint on this page and no network request in the code that does the work. JavaScript in your own tab reads the text, processes it and hands back the result. Nothing is stored between visits either, so reloading gives you an empty box again. You can confirm it by opening your browser's network panel and watching it stay quiet while you work.
Readable markup, unchanged content
Free, no account, no upload. Comments, CDATA and entities all exactly as you wrote them.
Back to the formatter