SVG use Using an Icon


Example

The <use> element is often used for reuseable icons, in collaboration with the <symbol> element. That looks like this:

<svg>
    <symbol viewBox="0 0 16 16" id="icon-star">
        <path d="M16 6.216l-6.095-.02L7.98.38 6.095 6.196 0 6.215h.02l4.912 3.57-1.904 5.834h.02l4.972-3.59 4.932 3.59-1.904-5.815L16 6.215" />
    </symbol>
</svg>

And the <use> element:

<svg>
    <use xlink:href="#icon-star"/>
</svg>

The <use> element copies the <symbol> and displays it. You can also override the styles on the <symbol> on individual <use> elements, e.g.

<style>
    .red {
        fill: red;
    }
</style>

<svg>
    <use class="red" xlink:href="#icon-star"/>
</svg>