Blog

Guides

SVG optimization: a practical guide for designers

SVGs exported from design apps carry a lot of extra code. Here is what an optimizer removes, which settings are safe, and how to avoid breaking icons and logos.

MD Rakib Shekh · Founder & Lead Architect

· 7 min read

On this page

You export an icon from your design app and open the file. Instead of a few tidy lines, you find editor notes, metadata, empty groups and coordinates with six decimal places. One file is no big deal. A whole icon set, inlined on every page and reviewed in every pull request, adds up.

SVG optimization strips out what the browser doesn't need and keeps the drawing the same. This guide explains what gets removed, which settings are safe, and the few cases where an optimizer can break an icon or logo.

What's inside an exported SVG

An SVG is a text file that describes shapes. Design apps add extra information on top of the shapes, mostly for their own use:

  • An XML declaration, a doctype and comments
  • Editor metadata and the app's own namespaces and attributes
  • Groups that contain nothing, or only one thing
  • Definitions, such as gradients, that nothing uses
  • Coordinates with long decimals, like 20.123456
  • Long color values, like #ffffff
  • Long, descriptive IDs, like gradientLongName

None of this changes how the image looks in a browser. It just makes the file longer and harder to read.

What an SVG optimizer does

Pagestro's SVG Optimizer runs your file through SVGO, the open-source SVG optimizer (SVGO). It uses SVGO's default set of steps, and lets you switch the main ones on or off.

SettingWhat it doesWhen to turn it off
Strip comments and doctypesRemoves comments, the doctype and the XML declarationA comment holds a note you must keep
Remove editor metadata and namespacesRemoves metadata, design-app attributes and editor-written desc textYou want every desc element kept
Collapse empty groups and defsRemoves empty groups and unused definitions, and merges needless groupsYour code adds content to an empty group later
Convert and shorten color hex codesWrites #ffffff as #fff, and so onRarely needed
Shorten IDs and update referencesRenames IDs to short ones, updates every reference, removes unused IDsSeveral SVGs share one page, or CSS or scripts target an ID
Minify stylesShrinks style blocks inside the SVGYou want the style block kept as written
Coordinate precisionRounds numbers to 1 to 4 decimalsUse 3 or 4 for very small or detailed drawings

After optimizing, Pagestro shows a list of what was cleaned and the file size before and after.

What stays

A good optimizer should never trade away how the image works. In current versions of SVGO, two important parts are kept by default.

  • The viewBox stays. SVGO's version 4 notes say removing the viewBox is no longer a default step, "to preserve scalability" (SVGO). The viewBox is what lets an SVG scale cleanly to any size.
  • The title stays. The same notes say removing titles is no longer a default, to preserve accessibility. Pagestro always keeps titles.

A desc element is removed only when it's empty or holds editor attribution, such as a "Created with" note (SVGO). Turn off the metadata setting to keep every desc.

Comments that start with an exclamation mark are kept even when comment stripping is on, so marked notes survive.

Watch out for these

Optimizers are safe for most files, but four things can catch you out.

Clashing IDs when several SVGs share a page

When you paste several optimized SVGs into one page, each may end up with the same short IDs. If two icons both define a gradient called "a", one icon can pick up the other's gradient. SVGO's own documentation warns about this (SVGO). The fix in Pagestro is simple: turn off Shorten IDs for icons you'll inline together, so each file keeps its original IDs. SVGO notes this won't help if two files already used the same ID before optimizing, so check for that and rename one by hand.

Hidden elements are removed

SVGO's default steps remove elements that are hidden, for example ones with zero size or hidden with CSS (SVGO). That's usually what you want, since hidden layers from the design app waste space. But if you hid part of the drawing on purpose, to reveal it later with a hover effect or script, it will be gone. Keep the original file and test interactive SVGs after optimizing.

The role attribute is removed

SVGO's defaults keep ARIA attributes such as aria-label, but remove the role attribute (SVGO). If you mark inline icons with role="img" for screen readers, add it back after optimizing.

Too little precision

Rounding long decimals can save a lot on detailed paths, but go too far and small details shift. Two decimals, the default, suits most icons and logos. If your drawing uses very small numbers, for example a viewBox of 0 0 1 1, every decimal matters more, so use 3 or 4.

Tip: Use the side-by-side view and zoom in on curves and thin lines. If anything looks off, raise the precision by one step.

How to optimize an SVG with Pagestro

Step 1. Open SVG Optimizer and drop in one or more SVG files.

Step 2. Choose your settings. The defaults suit most single icons and logos. Turn off Shorten IDs for icon sets you'll inline on one page.

Step 3. Check the result in the preview, the code view or both side by side, along with the list of changes and the size saved.

Step 4. Copy the code to paste inline into your HTML or component, or download the file. Several files download together as a ZIP.

The optimizer runs in your browser, so client logos and unreleased artwork aren't uploaded.

Safe settings by use

UseSuggested settings
A single icon or logo fileDefaults, precision 2
An icon set inlined on one pageDefaults, with Shorten IDs off
An SVG styled or animated by your own CSS or scriptsShorten IDs off, then test
A detailed illustration or mapPrecision 3, then compare side by side

When SVG isn't the right format

SVG is ideal for logos, icons, charts and simple illustrations. It isn't a good container for photos. An SVG that wraps a photo is mostly the photo itself, and an SVG optimizer cleans the markup, not the image inside it. Save photos as WebP or JPG instead, and see our guide on how to compress images for your website.

Only have a logo as a PNG or JPG? Convert Image can trace an image into a real vector SVG with up to 16 flat colors. Simple logos and icons trace cleanly. Photos come out posterized, because smooth shading turns into flat areas. For help picking between raster formats, read JPG vs PNG vs WebP vs AVIF.

Frequently asked questions

Will optimizing change how my SVG looks?

Usually not. Very low precision can shift small details, so check the preview. Two decimals suits most icons and logos.

Does the optimizer remove the viewBox?

No. Current SVGO defaults keep the viewBox, so your SVG still scales to any size.

Is the title kept for accessibility?

Yes, titles are always kept. A desc is removed only if it's empty or an editor note. The role attribute is removed, so add role="img" back if you use it.

Can I paste the result inline in HTML?

Yes. Copy the code and paste it into your HTML or component. Turn off Shorten IDs if several SVGs share the page.

Are my files uploaded?

No. The SVG is processed in your browser on your own device.

  • SVG
  • Icons
  • Web design
  • SVGO

Written by

MD Rakib Shekh

Founder & Lead Architect

Founder of Pagestro & UIXport. Specializing in WebAssembly browser tools, PDF processing, and high-performance design workflows.

Get new guides by email

Practical tips for PDFs, contracts and invoices. Unsubscribe anytime.