Skip to content

SVG optimiser

Make SVG icons and illustrations smaller with SVGO, check pixel by pixel that they still look the same, and see what a file contains that isn't safe to paste into a page or that a screen reader can't use. Files are optimised in your browser and never uploaded.

Runs in your browserSVGO 4.1.0Up to 50 files

Input

Paste SVG code, choose up to 50 SVG files (5 MB each), or drop them onto this card. Files are read and optimised in your browser and never uploaded.

Try a sample

Options

Also removes links (<a>), keeping what they contain, and animations that change links. Turn off only for SVGs that need to be interactive.

Removes embedded HTML. Diagram tools use it for labels, so check the result.

Uses the width and height, when they're plain numbers or px, so the image can scale.

Lets the SVG fill its container. Only applied when the file has a viewBox.

Offered when the file uses one paint colour.

Keeps IDs unique when several SVGs are inline on one page.

Repeats until nothing changes, up to 10 passes.

Indents the output for reading. It makes the file larger.

Precision

Decimal places kept in numbers. Lower is smaller, and can change how it looks.

How it's used

Keeps <title>, <desc> and role, and any id that ARIA refers to.

Advanced: SVGO plugins (34 of 34 on)

SVGO's default preset, in the order it runs. Plugins marked “Can change looks” are worth turning off first if the check finds visible differences.

  • Removes the DOCTYPE and its entity declarations.

  • Removes the <?xml …?> declaration, which browsers don't need.

  • Removes comments, keeping ones that start with ! (such as licences).

  • Removes attributes SVG 2 deprecated that have no effect, such as version.

  • Removes <metadata> blocks.

  • Removes data editors such as Illustrator, Inkscape and Sketch leave behind.

  • Trims and collapses whitespace in attribute values.

  • Merges several <style> elements into one.

  • Moves rules from <style> onto the elements they match.

  • Minifies CSS in <style> and style attributes, and drops unused rules.

  • Shortens IDs and removes unreferenced ones.

  • Removes <defs> content that has no ID, so nothing can use it.

  • Rounds numbers to the chosen precision and drops default px units.

  • Writes colours in their shortest form, such as #f00 for red.

  • Removes unknown elements and attributes, and ones set to their default.

  • Removes attributes on groups that their children can't inherit.

  • Removes stroke and fill settings that draw nothing.

  • Removes or shortens the old enable-background attribute.

  • Removes elements that are never drawn, such as zero-size shapes.

  • Removes empty text elements.

  • Turns rectangles, lines and polygons into paths where that's shorter.

  • Turns ellipses with equal radii into circles.

  • Moves attributes all children of a group share onto the group.

  • Moves a group's transform onto its paths so the group can go.

  • Removes groups that do nothing, moving their attributes to the child.

  • Rewrites path data with shorter commands and relative coordinates.

  • Combines and shortens transforms.

  • Removes attributes with empty values.

  • Removes empty groups, <defs> and other containers.

  • Joins neighbouring paths that share the same attributes.

  • Removes namespace declarations nothing uses.

  • Sorts attributes so the file compresses better.

  • Sorts <defs> children so the file compresses better.

  • Removes empty <desc> elements and ones an editor wrote.

Ready

Nothing to optimise yet

Paste SVG code, choose files or try a sample. You'll see the size saved, a check that it still looks the same, and what the file contains that could be unsafe or inaccessible.

How it works

SVGO, set up to keep what matters

The optimiser runs SVGO (opens in a new tab) 4.1.0 and its default preset in a background worker, so a large or hostile file can't freeze the page; a file that takes more than 10 seconds is stopped. SVGO 4 already keeps viewBox and <title>. On top of that, the tool keeps role and any id that aria-labelledby or aria-describedby points to, which the preset would otherwise remove, and adds a viewBox from plain width and height so the image can scale.

Looks the same

Both versions are drawn at the same size, on transparent and on white, and compared pixel by pixel. Rounding numbers can move an edge by a fraction of a pixel, so small differences in a few pixels count as tiny. Anything more is flagged as visible, with a view of the pixels that changed. A file that can't be drawn, for example because it needs an external image, is reported as not compared rather than passed.

Safety

An SVG shown with <img> or as a CSS background runs no script and loads nothing from outside the file. Pasted inline into HTML, it has neither protection. So the report lists scripts, event handlers, javascript: and other executable URLs, <foreignObject>, animations that change links, links themselves, a DOCTYPE, and every external reference, including url() and @import in styles. Each one says whether the optimiser removed it or it's still there. Before parsing, a DOCTYPE whose entities refer to other entities is refused, which stops the expansion attack known as Billion Laughs.

The previews here are always drawn as images, never inserted into the page. This tool removes what it names and lists the rest, but it isn't a sanitiser. To accept SVG uploads on a server, use a maintained sanitiser such as DOMPurify (opens in a new tab) with its SVG profile, and serve the files through <img>.

Accessibility

A <title> as the first child names an inline SVG, and <desc> describes it. Choose Meaningful image to add role="img" and a name linked with aria-labelledby, or Decorative to remove both and add aria-hidden="true". For an SVG in an <img>, the alt text is what counts, so the snippet carries it.

Not covered yet

  • React, Vue or other component output.
  • Icon sprites (<symbol> with <use>).
  • Compressed .svgz files, tracing raster images and editing paths.
  • Controls for animations in the preview.
  • Rewriting external references. They are listed with what to do about them.
  • Saving optimised files to a workspace project.