piapia123
en

SVG Minifier

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Shrink the SVG a design tool exported: drop comments and `<title>`/`<desc>`/`<metadata>`, collapse whitespace and newlines between tags, cut coordinate precision and remove unreferenced `id`s. Coordinates are where the bytes are: path data (`d`) is usually more than half the file, and it is one long list of numbers. Taking `M12.345678` down to `M12.35` typically saves twenty to thirty percent and is invisible — hence the 3-decimal default. ⚠️ A generic “strip all whitespace, delete every unused attribute” pass silently corrupts SVG, and corruption usually shows up as “a piece is missing” with no clear warning. So each rule here states what it will not touch: `viewBox` is never modified (remove it and the SVG can no longer scale, while it still looks right at one fixed size), spaces inside `<text>` are content (`Hello World` collapsing to `HelloWorld` is the classic accident), and a referenced `id` must never be dropped (`url(#a)` points at it, and the gradient disappears).

Features

  • Removes comments and title / desc / metadata (whole blocks, nesting included)
  • Collapses whitespace between tags while leaving `<text>` / `<tspan>` / `<style>` / `<script>` untouched
  • Coordinate precision 0–3 decimals for path, points, transform and similar attributes; 3 by default
  • Removes only unreferenced ids (`url(#a)`, `href="#a"` and SMIL `begin="a.click"` all count as references)
  • Never touches viewBox or preserveAspectRatio
  • Leaves colours, class names and style attributes alone (`#ff0000` never becomes `#ff0`)
  • Optional xmlns removal, labelled as applying only when inlining into HTML
  • Syntax-highlighted output with the resulting character count below it

How to use

  1. Paste your SVG source
  2. Toggle as needed — by default it does only the four safe things: comments, metadata, whitespace, 3 decimals
  3. For more, drop to 1–2 decimals or enable unreferenced-id removal
  4. Copy the minified result

FAQ

Why can viewBox not be removed?
Because `viewBox` defines the coordinate system: which part of the drawing maps onto which area. Remove it and `preserveAspectRatio` stops working too, so the SVG loses its ability to scale — while still looking correct at the one fixed size you set. The problem only appears when someone else drops it somewhere else (a distorted icon, or one corner showing). The dozen characters saved are not worth that risk, so this tool does not touch it at all.
Why is whitespace inside text left alone?
Because it is content. Removing the space in `<text>Hello World</text>` turns it into one word, and on screen that reads as “the text is cramped” — easily mistaken for a font problem. So collapsing happens only between tags; inside `<text>`, `<tspan>`, `<style>` and `<script>` everything is preserved verbatim. The last two are not markup languages at all, and have their own whitespace rules.
Does reducing precision distort the shape?
At 3 decimals, not visibly (on a 24px icon, 0.001 is about a fortieth of a screen pixel). At 1 decimal (0.1) you start to see slight polygonal faceting when the SVG is rendered large, especially on curves and diagonals; at 0 decimals (integers) small icons are fine, but magnification shows obvious error. Hence the 3-decimal default — judge the aggressive settings by asking whether this SVG will ever be displayed at a very large size.
Should xmlns be removed?
It depends how you will use the file. Inlined into HTML (the `<svg>` written directly into the page) it can go — a few bytes, and the parent document’s namespace takes over. But as a standalone `.svg` file, in a CSS `url()`, or as an `<img src>` target it must stay: without it the browser does not recognise the file, and the symptom is “nothing displays” while the file itself looks perfectly fine. That is why this option is off by default, with the condition stated on the label.

Related tools