XML Minifier
Remove the line breaks and indentation between XML elements to make a file smaller. Text values and attribute values are not touched.
or drop a file here · .xml, .txt · up to 20 MB
About the XML Minifier
Indentation makes XML pleasant to read, but every space and line break is sent over the network and stored on disk. For a large product feed, a sitemap with thousands of URLs, or an XML message stored inside another system, removing that padding can noticeably cut the size.
This minifier removes the whitespace that sits between tags, and optionally the comments, while leaving the actual data alone.
When to use it
- You are embedding an XML snippet in a JSON string, a database column or an environment variable and want it on one line.
- A partner’s portal limits the size of uploaded XML files.
- You want to know how much of a file is layout rather than content. The page shows the size before and after.
Worked example
Select Try an example. It loads a small catalogue spread over many lines with two-space indentation. Keep Remove comments ticked and select Minify XML.
The result is one line in which every tag follows the previous one with no gap, and the label above it shows how many bytes were saved. Now add a leading space to the second title, so it reads “ Godan”, and minify again: the space is still there, because it belongs to the text value, not to the layout.
Rules it follows
- Whitespace is removed only where an element contains other elements and no text of its own.
- Text values, attribute values, CDATA sections and processing instructions are never changed.
- An element marked xml:space=“preserve” is copied exactly, comments included.
Good to know
- The file must be well-formed first. Problems are reported with their line and column, as in the XML validator.
- Minifying cannot be fully reversed, because removed comments are gone. The XML formatter restores indentation, so keep your original if the comments matter.
- Web servers usually compress responses with gzip or Brotli, which already handles repeated whitespace well, so measure before expecting a big gain on the wire.
How to use XML Minifier
- Paste XML or open an .xml file.
- Choose whether to remove comments.
- Select Minify XML, check the size saved, then copy or download the result.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
Which whitespace is removed?
Only whitespace between tags in elements that contain other elements. Text such as <name> Asha </name> keeps its spaces, and so does any element marked xml:space="preserve".
Are CDATA sections and processing instructions kept?
Yes. CDATA sections, processing instructions and the DOCTYPE are copied unchanged. Comments are kept too unless you choose to remove them.
Can I undo the minification?
Paste the result into the XML formatter to indent it again. Removed comments cannot be brought back, so keep your original file.