freesozoFree tools, no sign-up (home)
All tools
Language: English
Tool number 25

SVG Optimizer (with a Visual Compare)

Paste an SVG or drop files, and they get smaller right away. Before and after are compared pixel by pixel, so you can check that no shape has broken before you use it.

Where the mistake is

Smaller SVG

    • Different pixels
    • Same pixels (shown faint)
    • Area with different pixels

    In CSS, the url("…") part goes straight into background-image: url("…");. For <img src="…"> in HTML, use the part between the quotes, starting with data:.

    What was done

        Your SVGs are processed only on this page. They aren't sent anywhere or saved in your browser; only the settings are saved. The shrinking is done with SVGO 4.1.0 (MIT licence).

        Settings

        Decimal places

        Fewer places make the file smaller, but shapes shift more easily. After changing this, check in "Preview" that nothing has moved.

        id

        Removes unused ids and shortens the ones in use to a, b and so on. Choose "Keep" if CSS or JavaScript refers to the ids. Choose "Add file name" when you put several SVGs straight into one page, so that their ids don't clash.

        Keeps only the viewBox, so the size is set by CSS or wherever you use the SVG. Adds a viewBox if there isn't one.

        For single-colour icons. The icon is then painted in the colour of the text around it (CSS color).

        Removes <script>, attributes such as onclick, and javascript: links.

        The line breaks and indents make it a little bigger.

        What to do next

        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)
        StepWhat it does
        removeDoctypeRemoves the DOCTYPE (the document type declaration)
        removeXMLProcInstRemoves the XML declaration (<?xml …?>)
        removeCommentsRemoves comments, but keeps ones that start with <!--! (a way of writing copyright notices and the like)
        removeDeprecatedAttrsRemoves deprecated attributes that are safe to remove (version on <svg>)
        removeMetadataRemoves <metadata> (information such as the author and the licence)
        removeEditorsNSDataRemoves elements and attributes written in by editors (Inkscape, Illustrator, Sketch and others)
        cleanupAttrsRemoves line breaks and extra spaces inside attribute values
        mergeStylesMerges several <style> elements into one
        inlineStylesMoves <style> rules that match only one element onto that element
        minifyStylesShortens the CSS and removes unused rules
        cleanupIdsRemoves unused ids and shortens the ones in use
        removeUselessDefsRemoves elements in <defs> that have no id (nothing can use them)
        cleanupNumericValuesRounds numbers to the set number of decimal places, and drops "px" where it can be left out
        convertColorsWrites colours in a shorter form (rgb() to #rrggbb, #rrggbb to #rgb and so on)
        removeUnknownsAndDefaultsRemoves elements and attributes that aren't in the SVG spec, and attributes set to their default value
        removeNonInheritableGroupAttrsRemoves attributes on groups (<g>) that the elements inside don't inherit
        removeUselessStrokeAndFillRemoves stroke and fill settings that have no visible effect
        cleanupEnableBackgroundRemoves enable-background (an old attribute) where possible
        removeHiddenElemsRemoves elements that can't be seen (such as ones with zero size)
        removeEmptyTextRemoves empty <text> elements
        convertShapeToPathTurns rectangles, lines and the like into a path when the path is shorter
        convertEllipseToCircleTurns ellipses (<ellipse>) whose two radii are equal into circles (<circle>)
        moveElemsAttrsToGroupMoves attributes shared by the elements in a group onto the group
        moveGroupAttrsToElemsMoves group attributes (such as transform) onto the elements inside
        collapseGroupsUnwraps groups (<g>) that do nothing
        convertPathDataWrites path data in a shorter form, and folds transforms into the path data
        convertTransformCombines several transforms into one and writes it in a shorter form
        removeEmptyAttrsRemoves attributes with empty values
        removeEmptyContainersRemoves empty containers (empty <g>, <defs> and so on)
        mergePathsMerges neighbouring paths into one where it can
        removeUnusedNSRemoves unused namespace declarations (xmlns:…)
        sortAttrsPuts attributes in a consistent order (which tends to compress better when sent)
        sortDefsChildrenPuts the contents of <defs> in a consistent order (for the same reason)
        removeDescRemoves <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

        HowExampleGood 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 backgroundbackground-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

        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.

        More tools