What to do next
- Paste SVG code or drop SVG files. You can drop as many files as you like at once.
- Read the line under "Preview". If it says they look the same, the result is ready to use. If it reports a difference, press "Difference" and the changed pixels show up in magenta.
- Change the settings to suit how you'll use it: "Remove width and height" if you'll size it with CSS, and "Change colours to currentColor" for an icon that should take the colour of the text.
- Press "Copy SVG" or "Save". With several files, use "Save all (ZIP)". For a CSS background, open "For CSS" and press "Copy for CSS".
Why SVGs get heavy
An SVG exported from an editor carries a lot of information that isn't needed to draw the picture, as the SVGO documentation also points out. The usual extras are:
- Notes editors write for themselves: the zoom level, the window position, layer names, and the name and version of the software. Browsers use none of it.
- Overly precise numbers: numbers with pointless trailing zeros, like 24.000000, and decimals finer than any screen can show.
- Values that are already the default: settings such as fill-opacity:1 (fully opaque) that change nothing when left out.
- Things with nothing in them: empty groups, unused definitions, comments and the XML declaration.
The "Icon exported from Inkscape" example on this page is a small 24×24 icon, yet it starts at 2,968 bytes. Made smaller, it comes to 405 bytes and looks the same.
What this tool does
The shrinking is done with SVGO (SVG Optimizer) 4.1.0. The tool runs SVGO's standard set of steps, called "preset-default", again and again until the file stops getting smaller.
The 34 steps in preset-default (in the order they run)
| Step | What it does |
|---|---|
removeDoctype | Removes the DOCTYPE (the document type declaration) |
removeXMLProcInst | Removes the XML declaration (<?xml …?>) |
removeComments | Removes comments, but keeps ones that start with <!--! (a way of writing copyright notices and the like) |
removeDeprecatedAttrs | Removes deprecated attributes that are safe to remove (version on <svg>) |
removeMetadata | Removes <metadata> (information such as the author and the licence) |
removeEditorsNSData | Removes elements and attributes written in by editors (Inkscape, Illustrator, Sketch and others) |
cleanupAttrs | Removes line breaks and extra spaces inside attribute values |
mergeStyles | Merges several <style> elements into one |
inlineStyles | Moves <style> rules that match only one element onto that element |
minifyStyles | Shortens the CSS and removes unused rules |
cleanupIds | Removes unused ids and shortens the ones in use |
removeUselessDefs | Removes elements in <defs> that have no id (nothing can use them) |
cleanupNumericValues | Rounds numbers to the set number of decimal places, and drops "px" where it can be left out |
convertColors | Writes colours in a shorter form (rgb() to #rrggbb, #rrggbb to #rgb and so on) |
removeUnknownsAndDefaults | Removes elements and attributes that aren't in the SVG spec, and attributes set to their default value |
removeNonInheritableGroupAttrs | Removes attributes on groups (<g>) that the elements inside don't inherit |
removeUselessStrokeAndFill | Removes stroke and fill settings that have no visible effect |
cleanupEnableBackground | Removes enable-background (an old attribute) where possible |
removeHiddenElems | Removes elements that can't be seen (such as ones with zero size) |
removeEmptyText | Removes empty <text> elements |
convertShapeToPath | Turns rectangles, lines and the like into a path when the path is shorter |
convertEllipseToCircle | Turns ellipses (<ellipse>) whose two radii are equal into circles (<circle>) |
moveElemsAttrsToGroup | Moves attributes shared by the elements in a group onto the group |
moveGroupAttrsToElems | Moves group attributes (such as transform) onto the elements inside |
collapseGroups | Unwraps groups (<g>) that do nothing |
convertPathData | Writes path data in a shorter form, and folds transforms into the path data |
convertTransform | Combines several transforms into one and writes it in a shorter form |
removeEmptyAttrs | Removes attributes with empty values |
removeEmptyContainers | Removes empty containers (empty <g>, <defs> and so on) |
mergePaths | Merges neighbouring paths into one where it can |
removeUnusedNS | Removes unused namespace declarations (xmlns:…) |
sortAttrs | Puts attributes in a consistent order (which tends to compress better when sent) |
sortDefsChildren | Puts the contents of <defs> in a consistent order (for the same reason) |
removeDesc | Removes <desc> (descriptions) that are empty or only name the software, like "Created with …" |
preset-default has no step that removes the viewBox or <title>. The viewBox is needed to resize the SVG, and <title> is needed by screen readers, so this tool keeps both as well.
This tool adds a few steps of its own:
- Adds xmlns and xmlns:xlink: both are needed once the SVG is saved as a file. Without them, the browser can't read the content as SVG, and shows an error or the raw markup instead. This often happens with hand-written SVGs and SVGs copied out of HTML.
- Turns style="…" into attributes such as fill="…": Inkscape writes colours and line widths together in style="…", so this saves a lot. It's skipped when the SVG contains a <style>, because changing the order in which the CSS applies could change how it looks.
- Removes xml:space: this attribute controls how spaces in text are handled, so it's removed only when there are no text elements (such as <text>).
- Removes scripts: you can turn this off in the settings. It's on to begin with.
How the look is compared
The original SVG and the smaller one are both drawn as images of the same size and compared pixel by pixel. The size is set so that the longer side is 400 pixels. Small icons are therefore compared enlarged, which catches shifts too small to see at their normal size.
- A pixel counts as different when its red, green, blue or transparency differs by more than 40 of 255 levels. Small differences, such as the soft edges of a line, aren't counted.
- If no pixels differ, the result is "Same". If fewer than 0.2% of all the pixels differ, it's "Slightly different", and above that, "Changed".
- "Difference" shows different pixels in magenta and unchanged pixels in faint black, with a magenta box around the area where the differences are.
What gets compared is how the SVG looks in the browser you're using now. Other browsers and editors may show it differently. An animated SVG is compared on whichever frame is showing at that moment.
Choosing the settings
Decimal places
Coordinates and sizes are rounded to this many decimal places. With 3, 12.34567 becomes 12.346; with 1, it becomes 12.3. Fewer places make the file smaller, but shapes shift a little. At the same setting, the shift shows more in an SVG whose viewBox numbers are small (a narrow range of coordinates). The starting setting is 3. After changing it, check the line under "Preview".
id
- Shorten: removes unused ids, and shortens the ones in use (by gradients and so on) to a, b and so on.
- Keep: leaves the ids alone. Choose it when CSS or JavaScript refers to the ids, or when an animation uses them.
- Add file name: puts the file name in front of each shortened id (id="a" in icon-a.svg becomes id="icon-a-a"). When several SVGs are written straight into one HTML page, ids from different SVGs can clash, and one SVG ends up using another one's gradient. The SVGO documentation describes this problem, and this setting avoids it.
Remove width and height
Removes width and height from the outermost <svg>. If there's no viewBox, one is made from the width and height and added. With a viewBox, the SVG scales to fit its container. Use this when you want CSS to decide the size. Afterwards, set the size with CSS or with the width and height of img.
Change colours to currentColor
Changes every colour in the SVG to currentColor, a keyword that stands for the value of the element's color property (its text colour). An icon written straight into HTML then takes the colour of the text around it, and you can change it with CSS color. On an SVG with two or more colours, everything turns into one colour, so use it only for single-colour icons. "Colour for currentColor" under "Preview" shows how the icon looks in another colour.
Remove scripts
Scripts never run in an SVG used in img or as a CSS background, but they do run when the SVG is written straight into HTML. For SVGs from other people, or ones you don't know the origin of, it's safer to remove them.
Using SVGs on the web
| How | Example | Good for, and what to watch |
|---|---|---|
| As an image | <img src="icon.svg" alt="…"> | The easiest way. Scripts inside the SVG don't run, and outside files (images and style sheets) aren't loaded. The page's CSS can't change the colours inside the SVG. |
| Straight into HTML | <svg …>…</svg> | The page's CSS can change colours and lines, and currentColor can match the colour of the text. When you add several, keep their ids from clashing ("Add file name"). |
| As a CSS background | background-image: url("data:image/svg+xml,…"); | Lets you use a small icon without adding a file. The "For CSS" output works as it is. As with images, scripts and outside files can't be used. |
- Attributes such as fill="…" can be overridden by the page's CSS. The SVG spec treats them as author-level CSS with a specificity of 0 that comes before the page's style sheets, so CSS aimed at the element wins. Besides making the file smaller, that's why this tool turns style="…" into attributes: it makes this kind of override easy.
- Give meaningful icons a name. <title> is a short description used by screen readers, and browsers usually show it as a tooltip when the pointer is over the icon. It goes first inside <svg>. If you use the SVG in img, write the name in alt instead.
- URL encoding gives shorter data URIs. Base64 makes data roughly a third larger. Because SVG is text, it's usually shorter to rewrite only the characters that mean something special in URLs (such as # and ") as %23 and so on.
- Servers often compress what they send. On the web, text files are usually sent compressed with gzip or similar. The "sent with gzip" figure in the result is the size after compressing with this browser's gzip, a rough guide to the size actually sent (it varies with how the server compresses).
Things to watch out for
- Embedded images don't get smaller. Photos and other PNG or JPEG images are sometimes embedded in an SVG. This tool leaves those parts as they are. To shrink the images, make them smaller separately with the Batch Image Converter and Compressor, then put them back in.
- Text appears in the viewer's fonts. Text written with <text> appears in a different typeface where that font isn't installed. For a logo, or anything that must look the same everywhere, convert the text to outlines (shapes) in your editor before exporting.
- Keep the original file. The smaller SVG no longer has the editor's layers or guides. When you need to edit it later, open the original.
FAQ
- Are my SVGs sent anywhere?
- No. Both the shrinking and the visual comparison happen only in the browser that has this page open. The SVGs aren't saved in your browser either; only the settings are.
- Does running it again make the file even smaller?
- The tool already repeats the steps until the file stops getting smaller, so putting the result through again changes almost nothing.
- "Add line breaks for reading" made it bigger than the original.
- The line breaks and indents add to the size. That option is for when you want code you can read. For use on the web, untick it.
- It says the look has changed.
- Check what changed with "Difference". If shapes have shifted, add decimal places. If the colours differ, untick "Change colours to currentColor". If CSS or JavaScript uses the ids, set id to "Keep".
- Can I use .svgz files?
- Yes. They're unpacked, made smaller and saved as ordinary .svg files.
- How many files can it handle at once, and how big?
- Up to 200 files, each up to 10 MB.
Sources
- SVGO, "Introduction" (SVGO is a library and command-line tool for making SVG files smaller; SVGs exported from editors carry a lot of redundant information such as editor metadata, comments, hidden elements and default values; the source code is under the MIT licence)
- SVGO, "Preset Default" (the standard set of steps and what's in it)
- SVGO, "cleanupIds" (ids can clash when several SVGs are put in one page)
- SVGO, "prefixIds" (the step that puts text in front of ids)
- SVGO, "removeDimensions" (removes width and height, and adds a viewBox if there isn't one)
- SVGO, "convertColors" (the setting that turns colours into currentColor)
- MDN, "Namespaces crash course" (an SVG file needs the namespace declaration, without which browsers don't recognise the content; xmlns:xlink is needed for xlink:href)
- MDN, "SVG as an image" (in img or a CSS background, scripts don't run and outside files aren't loaded)
- MDN, "viewBox" (with a viewBox, the SVG scales to fit its container)
- MDN, "<color> CSS type" (currentColor stands for the value of the element's color property)
- W3C, "Scalable Vector Graphics (SVG) 2", 6.6 Presentation attributes (attributes such as fill count as author-level CSS with a specificity of 0, coming before other style sheets)
- MDN, "<title> — the SVG accessible name element" (a short description used by screen readers, usually shown as a tooltip, and placed first)
- MDN, "Base64" (Base64 makes data roughly a third larger)
- MDN, "data: URLs" (characters with a special meaning in URLs are written as %XX)
- MDN, "Compression in HTTP" (text compresses well, and gzip and Brotli are the algorithms in use)
All checked on November 29, 2026. The example's byte counts are this tool's own results. Product names in this article are trademarks of their respective owners.