XML minify: the same document in fewer bytes
XML minify removes everything a parser does not need: the indentation, the line breaks between tags and, by default, comments. The result is a single line of markup that any XML parser reads exactly like the original. The status bar tells you the size before and after, so you can see what you gained.
Example: a sitemap
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<!-- generated nightly -->
<url>
<loc>https://example.com/</loc>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/about</loc>
</url>
</urlset>
Minified with Remove comments on (the default):
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/</loc><priority>1.0</priority></url><url><loc>https://example.com/about</loc></url></urlset>
The message reads 278 → 220 bytes (21% smaller). With the comment kept, the same file shrinks to 246 bytes, 12% smaller. Savings grow with nesting depth: a deeply indented SOAP response or a large config file often loses a much bigger share.
What is removed and what is kept
| Removed | Kept |
|---|---|
| Indentation and newlines between tags | The XML declaration and DOCTYPE |
| Comments (unless you untick the option) | Attributes and their values |
| Text inside elements; text on one line keeps its leading and trailing spaces | |
| CDATA sections and processing instructions |
Mixed content is left alone. In <p>Hello <b>big</b> world</p> the spaces are part of the sentence, so minifying cannot safely remove them and the element is output unchanged.
When minifying XML is worth it
- Payloads in code and tests. A one-line document is easier to store in a fixture, an environment variable or a string constant. The XML to string converter can minify and escape it in one step.
- Request bodies. SOAP and other XML APIs do not care about indentation, and smaller bodies are faster to log and transmit.
- Fixed size limits. Some message queues, form fields and database columns cap the length of what you store.
For files served over HTTP, gzip or Brotli compression already removes most of the cost of repeated whitespace. Minifying still helps a little, but it is not a replacement for server compression.
Whitespace edge cases
Three details can surprise you. First, text that spans several lines is trimmed: the line breaks and indentation before its first word and after its last word are removed, while line breaks inside the text stay. Second, an element marked xml:space="preserve" keeps its line breaks, so the output may not be strictly one line. Third, an element whose only content is whitespace, such as <sep> </sep>, comes out empty as <sep></sep>. If a single space is meaningful in your format, write it as   or put it in a CDATA section.
Things to check before you minify
Comments sometimes carry meaning: license headers, build markers or conditional sections read by a tool. If yours do, untick Remove comments. And if a document is not well-formed, it is not minified at all; the error is shown with its line and column so you can fix it first, or run it through the XML validator for a closer look.
To go the other way and make a minified file readable again, click Format here or open it in the XML formatter.
Privacy
Minification is done in your browser; the document is not uploaded. Loading from a URL goes through our server, and Save & Share stores the input on our server to create the link.