How to minify XML
- Paste the XML or drop the file onto the tool.
- Press Minify (Ctrl + Enter). Turn on Keep comments to keep notes such as licence headers.
- Format or the XML formatter restores the indentation when you need to read it.
Example: an icon from a design tool
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by the icon exporter -->
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<title>Bell</title>
<!-- outline -->
<path d="M18 16v-5a6 6 0 0 0-12 0v5l-2 2h16z"></path>
<circle cx="12" cy="20" r="2" />
</svg>
Minified, 301 characters become 224 (279 with Keep comments):
<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>Bell</title><path d="M18 16v-5a6 6 0 0 0-12 0v5l-2 2h16z"/><circle cx="12" cy="20" r="2"/></svg>
Both comments are gone, <path ...></path> became <path .../>, and the space before /> in <circle> was dropped.
What stays exactly as written
- Text inside elements, including spaces and line breaks.
- Mixed content: in
<p>Hi <b>there</b>, Sam</p>the spaces around<b>belong to the sentence, so the element is left alone. - Attribute values and quotes, CDATA, the XML declaration, the DOCTYPE and processing instructions.
It is not an SVG optimizer: path data, number precision and elements such as <title> are kept.
Where minified XML helps
Inline SVG in HTML or CSS, XML in a database column, and XML inside a JSON field. For the last, minify first, then run it through JSON escape. For JSON documents, use JSON minify.