Accessible SVG Icon Sprites: Reuse Symbols and Style Them with CSS

A download arrow, a check mark and a close icon may appear dozens of times on a single website. Copying the complete SVG markup for each occurrence works, but it also creates multiple places to edit the same shape. An SVG sprite gives you a reusable definition that can be referenced wherever an icon is needed.

A vector sprite stores drawing instructions for each icon. A bitmap sprite packs the icons into rectangular regions of one image. It can scale with text and inherit the foreground color of a button. For a download link, that leaves two separate jobs: give the arrow a reusable shape and give the link a name that describes what it downloads.

Choose the right icon format

FormatUseful whenWatch out for
Inline SVGOne-off illustrations or icons needing individual stylingRepeated markup
SVG symbol spriteRepeated interface iconsReference paths, IDs and accessibility
Bitmap spriteExisting pixel-art or fixed-size raster assetsDensity variants and background positioning
Individual image filesLogos and content imagesStyling and request strategy

A bitmap sheet is still useful when it fits the original artwork. Our CSS sprite creator helps map rectangles from an existing raster sheet to background-position rules. It does not build SVG symbols. Read CSS sprites in modern web design if you are deciding whether to keep an existing image sheet or move to vector artwork.

Define each shape once

Create a sprite container inside the document. Each symbol has a unique ID and a viewBox describing the internal coordinate system.

<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"
     class="icon-defs" aria-hidden="true" focusable="false">
  <symbol id="i-download" viewBox="0 0 24 24">
    <path d="M12 3v12m-5-5 5 5 5-5M4 16v4h16v-4"
          fill="none" stroke="currentColor" stroke-width="2"
          stroke-linecap="round" stroke-linejoin="round"/>
  </symbol>
</svg>

The symbol does not paint a standalone image. A use element inside a visible SVG references it:

<svg class="icon" aria-hidden="true" focusable="false">
  <use href="#i-download"/>
</svg>
.icon-defs { position: absolute; overflow: hidden; }
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

The viewBox creates a consistent 24-unit drawing canvas, while the outer SVG establishes the actual displayed size. The em unit makes the icon grow with the surrounding font. Explicit dimensions keep it from taking an unexpected amount of layout space.

Use distinct IDs such as i-download, i-search and i-close. Avoid duplicate IDs, especially when a component framework renders the same sprite multiple times on one page. In a server-rendered application, insert the global sprite once in the base layout.

Let the icon inherit the text color

The currentColor keyword uses the computed CSS color value. For a line icon, set stroke="currentColor"; for a filled silhouette, use fill="currentColor". This lets the icon adapt to button states and dark themes without maintaining two separate sets of drawings.

.action {
  color: #fff;
  background: #174ea6;
}
.action:hover { background: #123b7f; }

Apply class="action" to the link or button around the SVG. Its label and stroke will both be white. Avoid hardcoded black strokes in a monochrome icon that also needs to appear on dark surfaces. Conversely, a brand logo may require specific colors; do not blindly replace every fill in a multicolor illustration.

Use Color Studio to select foreground and background colors and inspect their contrast. Remember that controls need more than a readable default palette: hover, focus, disabled and selected states also deserve attention. Our accessible color system guide provides a broader approach to theme tokens and contrast.

Put accessible names on the meaningful element

The same download symbol can have different semantic roles depending on its surroundings.

Icon beside visible text. Hide the decorative icon from assistive technology. The visible words identify the link or button.

<a class="action" href="/report.pdf" download>
  <svg class="icon" aria-hidden="true" focusable="false">
    <use href="#i-download"/>
  </svg>
  Download report
</a>

Icon-only control. Provide an accessible name on the control itself. A title attribute or a tooltip alone is not a reliable substitute for a name. Consider visible text whenever space allows.

<a class="action" href="/report.pdf" download aria-label="Download report">
  <svg class="icon" aria-hidden="true" focusable="false">
    <use href="#i-download"/>
  </svg>
</a>

Standalone meaningful illustration. Expose the outer SVG as an image with an appropriate name, for instance using role="img" and aria-label="Download available" when no equivalent text exists nearby. Do not hide it if it is the sole carrier of information.

A symbol’s internal title is not a substitute for naming the actual control that references it. Reuse means that the same arrow could represent different actions in different contexts. Keep the text appropriate to the action.

Try a complete example

Save this as svg-icons.html and open it in a browser. The two links download a small example text file. The last row displays a check mark beside a status message.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Reusable SVG icons</title>
<style>
  :root { color-scheme: light dark; }
  body { font: 1rem/1.5 system-ui, sans-serif; margin: 2rem; }
  .icon-defs { position: absolute; overflow: hidden; }
  .icon { width: 1.25em; height: 1.25em; flex: none; }
  .control {
    display: inline-flex; align-items: center; justify-content: center;
    gap: .5rem; min-height: 44px; min-width: 44px;
    padding: .5rem .75rem; box-sizing: border-box;
    font: inherit; color: #fff; background: #174ea6;
    border: 1px solid transparent; border-radius: .4rem;
  }
  .control:hover { background: #123b7f; }
  .control:focus-visible { outline: 3px solid currentColor; outline-offset: -5px; }
  .status { display: flex; align-items: center; gap: .5rem; }
  @media (forced-colors: active) {
    .control { border-color: ButtonText; }
    .control:focus-visible { outline-color: ButtonText; }
  }
</style>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"
     class="icon-defs" aria-hidden="true" focusable="false">
  <symbol id="i-download" viewBox="0 0 24 24">
    <path d="M12 3v12m-5-5 5 5 5-5M4 16v4h16v-4"
          fill="none" stroke="currentColor" stroke-width="2"
          stroke-linecap="round" stroke-linejoin="round"/>
  </symbol>
  <symbol id="i-check" viewBox="0 0 24 24">
    <path d="m5 12 4 4L19 6" fill="none" stroke="currentColor"
          stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </symbol>
</svg>
<h1>Report actions</h1>
<a class="control" download="report.txt" href="data:text/plain,Example%20report">
  <svg class="icon" aria-hidden="true" focusable="false"><use href="#i-download"/></svg>
  Download report
</a>
<a class="control" aria-label="Download report" download="report.txt"
   href="data:text/plain,Example%20report">
  <svg class="icon" aria-hidden="true" focusable="false"><use href="#i-download"/></svg>
</a>
<p class="status">
  <svg class="icon" aria-hidden="true" focusable="false"><use href="#i-check"/></svg>
  Report ready
</p>
</body>
</html>

Both links use the native download attribute. Activating either saves the same text file. For actions that open a menu or toggle a preference, use a native button. The icon-only link has a minimum 44 CSS pixel target in both directions. The visible focus outline remains distinguishable without changing the layout. The forced-colors rule adds a border and uses a system color for the focus ring.

Open the browser accessibility tree and check that both links expose the expected name, while the decorative icons are not announced separately. The status also remains understandable without its check mark.

Move the sprite into an external file

An inline sprite avoids a separate network dependency but repeats its definitions in each new HTML document. For a multipage site with many shared icons, an external file can be a useful alternative. Save the symbol definitions in an SVG document named icons.svg next to your HTML page:

<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="i-download" viewBox="0 0 24 24">
    <path d="M12 3v12m-5-5 5 5 5-5M4 16v4h16v-4"
          fill="none" stroke="currentColor" stroke-width="2"
          stroke-linecap="round" stroke-linejoin="round"/>
  </symbol>
</svg>

Then change the reference:

<svg class="icon" aria-hidden="true" focusable="false">
  <use href="./icons.svg#i-download"/>
</svg>

Serve the file from the same origin with an appropriate image/svg+xml content type. External SVG references have browser security restrictions, so do not assume that adding a CORS header will make cross-origin use references work everywhere. Test over HTTP rather than relying on file URLs opened from disk.

If you use long-lived caching, version the filename when the contents change. A page referencing icons.a1b2.svg#i-download can retain that exact version while the next deployment introduces a new file. Keep old versions available while cached pages still refer to them. See our HTTP caching and ETags guide for debugging stale assets.

Avoid styling the internal elements of an external sprite with selectors that depend on reaching inside a referenced instance. Design the source to inherit the properties it needs, and test that behavior in the browsers you support.

Compare performance with real pages

Reducing duplicated SVG markup is not the same as reducing transferred bytes by the same amount. HTTP compression can remove much of the repetition in inline markup. An external sprite introduces a request on a cold visit but may be reused across subsequent pages.

Compare a page containing your typical icon count with an inline version and an external version. Record the HTML and sprite bytes, request count, rendering behavior and cache reuse. The Resource Timing tutorial explains how to separate transferred, encoded and decoded sizes when measuring an actual page.

For a small critical icon set, inline definitions may be entirely reasonable. For a very large library, split it into logical groups rather than forcing every page to download unused artwork. Do not use a separate HTTP request per icon merely to make the markup shorter without measuring the result.

Be careful with SVG from untrusted sources

SVG is markup, not just a collection of pixels. Depending on its embedding context, it may contain active content, references or constructs that you do not want on your page. Keep the sprite under source control and use reviewed assets. Do not concatenate arbitrary SVG supplied by users into your HTML.

If you publish a tutorial showing SVG source, use escaped text rather than accidentally rendering it. Our HTML encoder and decoder can prepare a source snippet for display; encoding is not a sanitizer for untrusted SVG.

Check the small details

  • At 200% zoom, verify that icons grow or remain legible and labels do not overlap.
  • Test dark mode, forced colors, keyboard focus and the accessible name of every icon-only control.
  • Check external symbol URLs, including the fragment ID, after deploying to a subdirectory.
  • Simulate a missing sprite. Controls with visible text should remain usable even if the graphic disappears.
  • Inspect caching on repeat visits before replacing a working asset strategy.

For reference, MDN explains the SVG color attribute and currentColor.

Premium is coming soon

An optional premium subscription to remove ads is planned. Subscriptions are not available yet.

You can keep using our free tools without an account.