← All guides

How to display both icons from one SVG sprite

Export the sprite, then place one visible SVG instance for each symbol you need. Copy the exact generated ID into each use reference and give the instance a visible size. Opening the sprite file by itself can legitimately show an empty canvas.

Keep a wide and a tall test icon

A toolbar needs two icons from one file. Start with different shapes so a swapped reference stands out. In the public example one drawing has a gradient and a circle on a wide background. The second shows a circle on a tall dark rectangle. An ID mistake is easier to spot with these than with two similar arrows.

Name the two symbols and place them

  1. Download both source files. Rename them source.svg and second.svg to reproduce the example IDs. Add them to SVG Sprite Generator in that order and leave the prefix at icon-.
  2. Download the result as sprite.svg and serve it beside your test page. For an inline sprite, insert its contents once into the HTML and use just the fragment beginning with # in the reference.
  3. For the external file, put <svg width="90" height="60"><use href="sprite.svg#icon-source"/></svg> in the page. Add a second SVG at 48 × 72 with href="sprite.svg#icon-second" on its use element. Open the page from the same web origin.

Check each symbol’s own coordinate system

The 917-byte sprite contains two symbols. icon-source has viewBox 0 0 300 200. Its coloured block points to the renamed gradient icon-source-paint. The second symbol, icon-second, keeps viewBox 0 0 160 240. The two example display sizes use those same proportions. Check the wide icon’s gradient and the tall icon’s circle in the page where they will be used.

Trace a blank icon from the page

Look at the generated symbol list after a filename or prefix change. Match the case and spelling in the page reference, confirm that the SVG file resolves at that relative path, then inspect the displayed element’s width and height. If the outline appears but a gradient is missing, check the fill reference against the ID inside the same symbol. Keep the two individual SVGs for places that expect a standalone image.

Further reading