XML Minifier
Paste XML to remove indentation, line breaks and comments and get a compact single-line file. The XML is checked for well-formedness first, so you get an exact line and column for any error, and CDATA sections and xml:space="preserve" content are never touched.
Last updated:
Your XML is processed locally in this tab and never uploaded. CDATA sections and xml:space="preserve" elements are kept exactly. Tip: Ctrl + Enter minifies.
How to use the XML Minifier
- Paste your XML into the left box, open a file or drop it on the box. A sample is loaded so you can see the result right away.
- Choose the options: how to treat whitespace inside text, and whether to remove comments, the XML declaration or processing instructions.
- Press Minify XML. With Live update on, the output refreshes as you type.
- Check the result: the status line confirms the XML is well-formed and the cards show the original, minified and gzipped size.
- Copy or download the minified file.
Example: before and after
<?xml version="1.0" encoding="UTF-8"?>
<!-- Exported 2024-05-01 -->
<order id="1042">
<customer>Ada Lovelace</customer>
<items>
<item sku="A1" qty="2"/>
<item sku="B7" qty="1"/>
</items>
<note><![CDATA[Leave at the door]]></note>
</order>becomes one line, with the comment removed and the CDATA text untouched:
<?xml version="1.0" encoding="UTF-8"?><order id="1042"><customer>Ada Lovelace</customer><items><item sku="A1" qty="2"/><item sku="B7" qty="1"/></items><note><![CDATA[Leave at the door]]></note></order>What is changed and what is kept
| Part of the document | What the minifier does |
|---|---|
| Indentation and line breaks between tags | Removed |
Spaces inside tags (<a x = "1" >) | Reduced to <a x="1"> |
| Line breaks and tabs inside attribute values | Turned into spaces (XML parsers do this anyway) |
| Text content | Whitespace runs collapsed to one space (or trimmed / kept, by option) |
Comments <!-- … --> | Removed (optional) |
CDATA <![CDATA[ … ]]> | Kept exactly |
Elements with xml:space="preserve" | Kept exactly, including whitespace and comments |
Entities such as & and © | Kept as written |
| DOCTYPE and internal DTD subset | Kept, with extra whitespace removed |
| XML declaration, processing instructions | Kept (removable by option) |
When to minify XML
- Payloads and storage. Smaller SOAP requests, API responses, message-queue payloads and database columns, especially where gzip is not applied.
- Embedding. One-line XML is easier to put in a JSON string, an environment variable or a test fixture.
- SVG files. SVG is XML, so removing editor comments and indentation trims icons and illustrations. Keep
xml:spaceor text whitespace where text layout matters. - Need it readable again? Use the XML Formatter to pretty-print a minified file.
Frequently asked questions
What does an XML minifier remove?
It removes the whitespace that only exists for readability: indentation and line breaks between tags, extra spaces inside tags, and (optionally) comments. Element names, attributes, attribute values, text, entities and CDATA content are kept, so the minified document describes the same data.
Is it safe to remove whitespace between tags?
For data and configuration XML (feeds, sitemaps, SOAP, API payloads, settings) yes, because whitespace-only text between elements is not meaningful there. In mixed content, such as XHTML or DocBook, a space between two inline elements may matter. Mark such elements with xml:space="preserve" (which the minifier respects) or choose Keep text exactly.
Are CDATA sections and comments handled correctly?
CDATA sections are copied exactly, including their whitespace and markup, because their content is character data. Comments are removed by default since parsers ignore them; untick Remove comments to keep them, for example for license headers. Comments inside xml:space="preserve" elements are always kept.
Does the tool validate my XML?
Yes. Before minifying, the input is parsed with the browser's built-in XML parser. If it is not well-formed (mismatched tags, an unquoted attribute, an undefined entity like or a bare &), you get the parser's message with the line and column, and nothing is output. It checks well-formedness only, not a DTD or XSD schema.
Should I remove the XML declaration?
The declaration <?xml version="1.0" encoding="UTF-8"?> is optional for UTF-8 and UTF-16 documents, so removing it saves a few bytes. Keep it if the file uses another encoding such as ISO-8859-1 or if a consumer expects it.
How much smaller will my XML get?
Pretty-printed XML usually shrinks by 10 to 40 percent, depending on how deeply it is indented and how many comments it has. The Gzipped card shows the size after gzip compression, which servers typically apply: whitespace compresses very well, so minifying matters most when files are stored or sent uncompressed.
Is my XML uploaded?
No. Parsing and minifying happen entirely in your browser, so configuration files, API responses and other private data stay on your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.