Menu

1 / 2

How to Create an SVG Icon Sprite for Your Website

DEV Community: html·Svg/icons·20 days ago
#kEbsriT6
#devto2#devto#dev#home#search
Long article (2271 words) — no AI summary yet.
Reading 0:00
15s threshold

Build a small navigation example with Home, Search, and a dismiss button using three icons from the same set. You will paste SVG code into the free SVG Sprite Generator , copy its output, and use the resulting symbols in a web page. No framework or build plugin is needed.

Once the generated sprite is included in your page, a visible icon needs only a reference to its symbol. Here is the Home link used in this example:

<a href= "#home" > <svg class= "icon" width= "24" height= "24" aria-hidden= "true" focusable= "false" > <use href= "#icon-home" ></use> </svg> Home </a>

Enter fullscreen mode

Exit fullscreen mode

.icon { width : 1em ; height : 1em ; fill : currentColor ; }

Enter fullscreen mode

Exit fullscreen mode

This short snippet assumes icon-home is already defined in the document. The steps below create that definition; section 3 contains the complete page you can copy.

When a sprite fits

A sprite defines each icon once inside a <symbol> .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.