TL;DR: Paste XML and press Minify XML. The document is validated first, indentation and whitespace-only text nodes between elements are removed, and the compact result appears in the right pane with a before/after byte count. Text, attribute values, comments and CDATA sections are kept.
XML is verbose twice over: tags repeat, and pretty-printed files spend a lot of bytes on indentation. For a document that a parser will read anyway, that indentation is pure overhead — in deep documents it can be a third of the file. Minification removes it without touching the information the document carries.
This minifier is the same engine as the XML Formatter, run in reverse. Because the document is parsed into a tree before it is compacted, the output stays well-formed: tags remain balanced, attribute values keep their quotes and every entity reference survives.
How to minify XML
Paste the pretty-printed XML
Paste from your editor or load the sample. The pane header shows the exact input size in bytes, measured the same way the output will be.
Press Minify XML
The document is validated, whitespace-only text nodes between child elements are dropped, and everything else is emitted without newlines or indentation.
Check the size change
The status line shows input bytes, output bytes and the percentage saved. Size is measured in UTF-8 bytes, not characters, so non-ASCII content is counted correctly.
Copy the result
Copy result puts the compact XML on your clipboard. If you need to read it again later, paste it back here or into the formatter and it will be re-indented.
What minification removes and what it keeps
| Removed | Kept |
|---|---|
| Indentation spaces and tabs between elements | Element and attribute names and their order |
| Newlines between tags | Attribute values, including their quotes |
| Whitespace-only text nodes inside element-only content | Text content with any non-whitespace character, byte for byte |
| Comments (this tool does not silently delete them) | |
| CDATA sections, processing instructions and DOCTYPE declarations | |
Entity references such as & or © |
Keeping comments is a deliberate choice. Many minifiers strip them, which is fine for build artifacts but risky for hand-edited files: a comment may hold a TODO list, a license header or a note about why an element exists. This tool removes bytes, not decisions. If comments should go, delete them deliberately before minifying.
How much smaller does XML get?
The saving depends on nesting depth, indentation width and how much text the document contains. A configuration file with 4-space indentation and elements nested six levels deep loses a lot of whitespace; a flat document with two levels and long text values loses almost nothing. In practice 10–40% is a normal range for indented configuration and generated data, and the before/after counter reports the real number for your specific file instead of an estimate.
Two examples make the range concrete. A 120 KB Spring configuration with four-space indentation typically drops to roughly 80 KB. A flat 2 KB API response whose elements carry long string values may drop by only a few percent. Both results are correct: the tool reports what happened rather than promising a ratio.
Does minifying XML break anything?
Minification changes text nodes, and that sentence deserves attention. Whitespace-only text nodes between child elements are removed on purpose. If a consumer treats that whitespace as content, the output will behave differently. The classic example is XHTML: <b>a</b> <b>b</b> has a significant space between the two elements, and it is preserved here because it sits in mixed content. An element such as <block> <line/> </block>, where the whitespace around the child is insignificant, is compacted.
Any text value containing a non-whitespace character is copied byte for byte, including leading and trailing spaces around that character. A newline inside a <message> element survives; the newline just before the closing tag does not, because it is whitespace-only and belongs to element-only content.
If you are unsure whether a document is whitespace-sensitive, format it first and keep the pretty version. A format → minify → format round trip returns the same text because the formatter is content-preserving, so you can compare before and after without guessing.
Minify vs gzip: which should you use?
They solve different problems and combine well. Minification removes bytes from the document itself, so the saving survives storage, copy-paste, parsing and embedding. gzip or Brotli compress the byte stream and usually shrink a file by 80–95%. If the XML travels over HTTPS and the server already compresses responses, gzip captures most of the redundancy — but minification still helps with memory use, log volume and files bundled inside an application.
For most web payloads the practical advice is simple: minify what you ship, then let the transport compress it. For a configuration file consumed on a device or embedded in firmware, minification alone is the win.
When should you minify XML?
- Build artifacts: minify generated XML before packaging so installers and app bundles carry fewer bytes.
- Embedded documents: Android layouts, SVG and similar XML-derived formats are parsed at runtime, not read by humans, so indentation buys nothing.
- Log and telemetry payloads: smaller batches cost less to transmit and store.
- Size-limited environments: firmware, embedded devices and message queues with hard payload limits.
- Not for pull requests. Hand-edited configuration should stay formatted — reviewability matters more than bytes in a repository.
Limits and privacy
Everything happens in your browser; the document is never uploaded. As with the formatter and validator, input is capped at 2 MB (2,097,152 bytes) so a large paste cannot exhaust the tab’s memory. Oversized input is refused with its size and the limit. For larger files, xmllint --noblanks or a build plugin is the right tool.
Minification runs only on well-formed XML. That ordering matters: removing whitespace from a document with unbalanced tags would produce output that is smaller and wrong, so the tool validates first and refuses to emit anything when the input is broken.
Frequently asked questions
Does minifying XML break it?
The output stays well-formed as long as the input is well-formed, because the minifier validates first. The thing to watch is whitespace that carries meaning: text containing real characters is preserved byte for byte, but whitespace-only text nodes between child elements are removed.
How much smaller will my file be?
Usually 10–40% for indented configuration files; flat files with long text values shrink much less. The tool reports the exact before/after byte counts and the percentage saved for your document.
Does the minifier remove comments?
No. Comments are preserved. Silently deleting them would change the document in ways a size counter cannot show, so removing comments is left to you.
Can I minify a 5 MB XML file?
No. Input is capped at 2 MB (2,097,152 bytes) to keep the browser responsive; larger files are refused with a message that states the size and the limit. Use xmllint --noblanks or a build plugin for large documents.
Is my XML uploaded when I minify it?
No. Minification runs locally in your browser and makes no network request with the document. Nothing is stored.
Can I format the minified result again?
Yes. Paste the minified output back into this page or into the XML Formatter page and it will be re-indented. The round trip is content-preserving, so the text values are unchanged.
Related XML tools
XML Formatter
Paste XML and get clean, indented output with syntax checking.
Open →XML Formatter Online
Format XML online in any browser — no install and no upload.
Open →XML Validator
Check XML and get exact line and column errors in plain English.
Open →About
Who runs this site and how the tools are built and tested.
Open →