How to use the SVG optimizer
- Paste SVG markup in the left pane, or drop an
.svgfile on it. - The Preview tab shows the optimized image on a checkerboard, so transparent areas are visible. The Optimized tab shows the markup, which you can copy or download.
- The status bar shows the size before and after. The Illustrator export in the sample goes from
756 B → 317 B (−58%).
Optimization uses SVGO with its default preset, the same set of plugins you get from npx svgo. On SVGs with thousands of paths, the path-merging step is skipped so the result stays fast, and a warning tells you so.
Options
- Output: SVG, or React JSX for a ready-to-use component (see below).
- Precision: how many decimals numbers keep, from 1 to 5. Lower values give smaller files; 3 is SVGO’s default.
- Multipass: runs the optimizations repeatedly until the file stops shrinking. It is usually worth the extra few milliseconds.
- Prettify: indents the SVG output so it’s readable, at the cost of a few bytes.
- Remove viewBox (More options): off by default. See the FAQ before turning it on.
- Remove scripts (More options): on by default.
What gets removed
From the sample, SVGO removed the XML declaration and the Illustrator comment, the empty <metadata> and <defs>, the unused id="Layer_1", version and xmlns:xlink, and the px units. It rewrote stroke="#000000" as #000 and 2.000000 as 2, lowercased the color in the style attribute, folded the nested group into its parent and turned the <polyline> into a shorter <path d="m7.5 12.5 3 3 6-6.5"/>. The <title> stayed, because screen readers use it.
React JSX output
With Output: React JSX, an icon like a 24×24 diamond becomes:
export default function Icon(props) {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" {...props}>
<path fill="none" stroke="currentColor" strokeWidth="2" d="m12 2 10 10-10 10L2 12Z" />
</svg>
);
}
Attributes are converted to the names React expects: stroke-width becomes strokeWidth, class becomes className, xlink:href becomes xlinkHref, and data-* and aria-* stay as they are. A style="fill: red; stroke-width: 2" string becomes the object style={{ fill: "red", strokeWidth: "2" }}. Event handler attributes are left out, because React needs functions there. Use stroke="currentColor" or fill="currentColor" in the SVG if you want the icon to take the text color.
Errors
SVGO parses the file as XML, so markup that isn’t well-formed is rejected with the position of the problem. For example, a <rect> that is never closed gives Unexpected close tag at line 1, column 95, where the parser reached </svg>. Run the file through the XML Formatter to see the structure, fix the tag, and paste it back. A file whose root isn’t <svg>, such as an HTML page, is rejected too.
Related tools
To embed the optimized SVG in CSS or HTML as a data URI, encode it with Base64. To adjust a fill or stroke color, convert it with the Color Converter. The QR Code Generator produces SVG output that you can optimize here too.
Frequently asked questions
Will the optimized SVG look different?
It shouldn't at the default precision of 3 decimals. SVGO's default preset only applies safe changes: removing editor data, comments and hidden elements, shortening numbers, colors and path commands, and merging compatible paths. Very small icons drawn on a fine grid can shift slightly at precision 1; compare the preview, and raise the precision if you see a difference.
Should I remove the viewBox?
Almost never. Without a viewBox, the SVG no longer scales when you change its width and height in CSS: the drawing keeps its original size and gets cropped or leaves empty space. The option exists for the rare case where the SVG is always shown at its natural size. The tool warns you when it removes one.
What happens to scripts in the SVG?
By default, <script> elements, event handler attributes such as onload and onclick, and javascript: links are removed, and a warning lists what was removed. Turn off Remove scripts under More options to keep them. The preview always shows the SVG as an image, so its scripts never run on this page.
How do I use the React component?
Choose Output: React JSX, then save the code as Icon.jsx (or .tsx). The props are spread onto the svg element, so <Icon width={16} className="text-red-500" /> overrides the size and adds a class. The title element is kept, which gives the icon an accessible name.
Is my SVG uploaded?
No. SVGO runs in your browser, and the file never leaves your device.
Last updated