Loading...

SVG Minifier Online — Compress SVG Code Free

An SVG minifier that strips comments, XML declarations, and unnecessary whitespace from raw SVG markup to shrink file size while keeping the graphic pixel-identical. It collapses indentation and line breaks between tags and tidies extra spacing inside attributes, but leaves text and tspan content untouched so labels and captions never shift position or lose a meaningful space. This is useful for icon sprites, logos, and any inline SVG destined for production, where every stripped byte helps page load speed. Runs entirely in your browser — no uploads, no sign-up, and nothing is ever sent to a server.

Features

  • Comment and declaration stripping

    Removes <!-- comments --> and, optionally, the leading <?xml ...?> declaration, which browsers do not require when an SVG is inlined in HTML.

  • Safe whitespace collapsing

    Collapses indentation and line breaks between tags into a single compact stream without altering the rendered shape, path data, or transforms.

  • Text-safe minification

    Whitespace inside <text> and <tspan> elements is left exactly as written, since spaces there are visually significant and collapsing them would change how labels render.

  • Attribute spacing cleanup

    Extra spaces between attributes inside a tag are collapsed to one, while the attribute values themselves — including path data and transform lists — are never touched.

How to minify SVG online

Compress raw SVG markup in seconds without changing how it renders.

  1. Paste your SVGDrop the full SVG markup, including the outer <svg> tag, into the left panel.
  2. Toggle the XML declaration optionLeave "Strip XML declaration" checked to remove the <?xml ...?> header, or uncheck it if you need to keep the file as a standalone, spec-compliant .svg document.
  3. Read the minified outputThe compressed markup appears instantly in the right panel along with byte counts and the percentage reduction.
  4. Copy or downloadClick Copy to grab the minified SVG as text, or Download to save it as a .svg file.

Examples

Minify an icon with comments and indentation

Input
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <!-- outer circle -->
  <circle
    cx="12"
    cy="12"
    r="10"
  />
</svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/></svg>

The XML declaration and comment were removed, and whitespace between and inside tags was collapsed to a single stream.

Frequently Asked Questions

What does an SVG minifier do?
It removes characters that have no effect on how the SVG renders — comments, the optional XML declaration, and whitespace used only for human-readable formatting — so the file downloads and parses faster without any visual change.
Is it safe to remove the XML declaration?
Yes, in almost every real-world case. Browsers render inline SVG and SVG referenced via <img> or CSS without needing the <?xml ...?> header. Keep it only if the file must remain a strictly spec-compliant standalone XML document for some other tool in your pipeline.
Will minifying change how my icon or graphic looks?
No. The minifier only strips comments, declarations, and non-significant whitespace between tags and attributes. Path data, transforms, colors, and every other attribute value are left byte-for-byte identical.
Why does the tool avoid touching whitespace inside <text> elements?
Spaces inside <text> and <tspan> content are part of the rendered label — collapsing "Hello World" to "Hello World" or removing a deliberate leading space would visibly change the text layout. This minifier leaves that content exactly as you wrote it.
Can I minify SVGs exported from Illustrator or Figma?
Yes. Exported SVGs often carry verbose formatting, editor metadata comments, and an XML declaration — all of which this tool strips. For further savings, run the output through a dedicated SVG optimizer like SVGO that can also simplify path data and remove unused attributes.
Does this tool optimize path data or remove unused IDs?
No. This is a whitespace-and-syntax minifier, not a full SVG optimizer — it does not simplify path coordinates, merge shapes, or strip unused defs and IDs. It focuses purely on safe, reversible-in-effect formatting cleanup.