FormatterHQ

XML Minify

Strip indentation, line breaks and comments from XML and see exactly how many bytes you saved. Text content and CDATA are kept, so the data means the same thing.

Input XML
Output XML
Ready.

How to use the XML Minify

  1. Paste the XML, upload a file or load one from a URL.
  2. Leave Remove comments ticked to drop <!-- --> blocks, or untick it to keep them.
  3. Click Minify. The status bar shows the size before and after, for example 278 → 220 bytes (21% smaller).
  4. Copy or Download the result. Click Format to expand it again.

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

RemovedKept
Indentation and newlines between tagsThe 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 &#x20; 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.

Frequently asked questions

Does minifying XML change the data?
No. Whitespace between tags and, optionally, comments are removed. Attribute values, CDATA, the declaration and text written on one line stay as they were; text that spans several lines only loses the whitespace before and after it.
Why did the size barely change?
The input was probably already compact, or most of its bytes are text content, which is kept. Mixed-content elements are also left untouched to protect the spaces between words.
Can I keep comments when minifying?
Yes. Untick Remove comments before you click Minify. Comments are then kept in place, and only indentation and line breaks are removed.
Is minified XML still valid XML?
Yes. Whitespace between elements is optional in XML, so the minified document is well-formed as long as the original was. The tool refuses to minify input that is not well-formed.

Last updated October 3, 2026

Related tools

JSON Minify Minify JSON by removing whitespace and line breaks. Shrink payloads for APIs, storage and embedding, and see the bytes saved. CSS Minifier Minify CSS online: remove whitespace and comments and merge rules to reduce stylesheet size. HTML Minifier Minify HTML online including inline CSS and JavaScript. JavaScript Minifier Minify JavaScript online with Terser to shrink file size for faster websites. XML Parser Parse XML online and inspect the resulting object tree with elements, attributes and text nodes clearly separated. XML Pretty Print Pretty print XML in the browser, with matching commands for xmllint, xmlstarlet, Python and .NET when it belongs in a script. Sort XML Online Sort XML elements alphabetically by tag name or by an attribute value, at every level. Optionally sort attributes as well. XML to String Converter Convert XML to an escaped string literal for Java, C#, JavaScript or JSON. Minify first or keep lines as concatenated strings. XML Validator Validate XML online for well-formedness. Find unclosed tags, bad nesting and invalid characters with exact line and column numbers. XML Viewer View XML as a collapsible tree alongside formatted text. Inspect elements, attributes and values in any XML document. XML XSL Transform Apply an XSLT stylesheet to XML online and preview the result. Produce HTML, XML or text output from any XML document. XPath Tester Test XPath expressions online against your XML. See matched nodes, attributes, strings, numbers or booleans instantly.