Home › Developer Tools › XML Minifier

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:

Original–
Minified–
Gzipped–
Saved–

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.

Advertisement
Advertisement

How to use the XML Minifier

  1. 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.
  2. Choose the options: how to treat whitespace inside text, and whether to remove comments, the XML declaration or processing instructions.
  3. Press Minify XML. With Live update on, the output refreshes as you type.
  4. Check the result: the status line confirms the XML is well-formed and the cards show the original, minified and gzipped size.
  5. 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 documentWhat the minifier does
Indentation and line breaks between tagsRemoved
Spaces inside tags (<a x = "1" >)Reduced to <a x="1">
Line breaks and tabs inside attribute valuesTurned into spaces (XML parsers do this anyway)
Text contentWhitespace 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 &amp; and &#169;Kept as written
DOCTYPE and internal DTD subsetKept, with extra whitespace removed
XML declaration, processing instructionsKept (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:space or 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 &nbsp; 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.

Related tools

XML FormatterBeautify, validate and minify XML with a collapsible tree view.XML to JSONConvert XML to JSON with validation.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.
See all 41 Code Formatters & Validators →