SVG for speed: icons, logos and illustrations

When SVG is the lightest choice, four ways to put it on a page, how to shrink files with SVGO, how to use a sprite, and the mistakes that make SVG heavy.

IntermediateHow-to7 min readUpdated October 30, 2026

In this guide
  1. What SVG is good at
  2. Four ways to put SVG on a page
  3. Make the file small
  4. Size it and place it
  5. Use a sprite for many icons
  6. Serve it well
  7. When SVG is the wrong tool
  8. How to check
  9. Mistakes to avoid
  10. Check your own page
  11. Sources

What SVG is good at

MDN describes SVG as an XML-based vector format that stores an image as drawing commands for shapes, lines, colors and filters. It calls SVG ideal for diagrams, icons and other images that can be drawn accurately at any size, and a good choice when the display size is unknown or varies, since SVG scales smoothly. It adds that SVG is not generally useful for bitmap or photographic images, although a bitmap can be placed inside an SVG. An SVG that wraps a photo is the photo's bytes plus extra markup. Use a photo format for that. See image formats.

SVG is text, so it also compresses well on the way to the visitor. MDN notes that SVG can be compressed in transit with HTTP compression. The Web Almanac counts SVG among the text formats that gain from it. See text compression.

SVG is also the usual cure for two heavy habits: PNG logos exported at several sizes, and an icon font that carries hundreds of icons when the page uses a handful. See web fonts and speed.

Four ways to put SVG on a page

WayGood forWatch out for
<img src="logo.svg">Logos and illustrations used on many pagesIt is an image: MDN says scripts are disabled and external resources, such as stylesheets, are not loaded. The page's CSS does not reach inside
Inline <svg> in the HTMLA few small icons you want to style or animateThe code travels inside every page's HTML and is not cached on its own. Repeated many times, it grows the DOM
A sprite: <use href="icons.svg#id">Many icons used across the siteThe icons appear when the sprite file arrives. MDN says the same-origin policy may apply
CSS background-image: url(...)Decorative shapesThe browser finds it only after reading the CSS

For most sites the best mix is an img for the logo, inline SVG for the two or three icons in the first screen, and a sprite for the rest.

Make the file small

Files exported from vector editors carry leftovers. The README of SVGO, a free Node.js optimizer, says they usually contain a lot of redundant information: editor metadata, comments, hidden elements, and default or suboptimal values that can be removed or converted without changing how the image looks.

npm install -g svgo
svgo logo.svg -o logo.min.svg

I ran SVGO 4.1 on a hand-made 1.9 KB file written in the style of an Inkscape export. With the default settings it produced a 0.5 KB file. It removed the XML declaration, the comment, the editor's namespaces and settings, the metadata, an empty group and the "Created with" description. It shortened the path data. It kept the viewBox and the title. Your files will differ, and this one is only an example.

Three things in the defaults deserve a look:

// svgo.config.mjs
export default {
  plugins: [
    { name: 'preset-default', params: { overrides: { cleanupIds: false } } },
    'prefixIds',
  ],
};

Run it with svgo logo.svg --config svgo.config.mjs -o logo.min.svg. Keep the original export, and look at the result before you publish it. An optimizer cannot remove detail that you drew, so fewer points in a path and fewer layers in the source still help most.

Size it and place it

Use a sprite for many icons

MDN says the symbol element defines graphic templates that a use element draws, and that use can load them from an external file by naming the file and a fragment. Put the icons in one file, and the browser fetches and caches it once:

<!-- /img/icons.svg -->
<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="check" viewBox="0 0 24 24"><path fill="currentColor" d="M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z"/></symbol>
  <symbol id="close" viewBox="0 0 24 24"><path fill="currentColor" d="M19 6.4 17.6 5 12 10.6 6.4 5 5 6.4 10.6 12 5 17.6 6.4 19 12 13.4 17.6 19 19 17.6 13.4 12z"/></symbol>
</svg>

<!-- in the page -->
<svg class="icon" width="24" height="24" aria-hidden="true"><use href="/img/icons.svg#check"></use></svg>

I tested this in headless Chromium: two icons made one request for the sprite, and each icon took the color of its own svg element through currentColor. MDN warns that the copied content is not exposed to CSS, and that styles reach it only through inheritance, so set colors with properties that inherit. Serve the sprite from your own domain, because MDN notes that browsers may apply the same-origin policy to use.

The icons draw when the sprite arrives. For an icon in the first screen, inline that one instead. A decorative icon takes aria-hidden="true". An icon that carries meaning needs a short title as the first child of the svg, which MDN says gives an accessible, short-text description, and role="img", because web.dev's accessibility course says assistive technology skips inline SVG by default. If visible text already describes it, point to that text with aria-labelledby. For an img that points to an SVG file, MDN advises adding role="img" too, because of a VoiceOver bug.

Serve it well

When SVG is the wrong tool

How to check

  1. List the SVG files. In the Network panel, filter by mime-type:image/svg+xml and sort by size. A file in the hundreds of kilobytes is worth a look. See the Network panel.
  2. Check the headers of each: Content-Encoding, Content-Type and Cache-Control.
  3. Do not rely on Lighthouse for this. Its Improve image delivery check skips files of the type image/svg+xml, so a heavy SVG is never flagged.
  4. See the size that travels. A command such as gzip -9 -c logo.svg | wc -c shows a close estimate of the compressed size.
  5. View the page source. Count the inline SVGs and look for repeated ids.

Mistakes to avoid

Check your own page

Run the free audit and note the largest images. Then filter the Network panel by mime-type:image/svg+xml and sort by size. Optimize the biggest file with SVGO, compare the sizes and confirm that it looks the same.

Sources

Start here

Free website audit

Live Google data for any public page: mobile and desktop.

Mobile + desktop · Lighthouse lab test · Real-user Chrome data when Google has it

Rather have this done for you? Speed optimization · Book a call

Related guides

All guides →