Code

SVG

Symbols & Use

Advanced Define reusable icon components with <symbol> and stamp them with <use> — overriding size, position, and fill at each usage site. MDN symbol

icon-heart — different sizes & coloursicon-star — icon reuse in a rating stripstatus icons via <use>Success — task completedWarning — review neededDisabled — not availableicon-arrow — rotated with transformicon grid
<defs>
  <!-- Define symbol with its own viewBox -->
  <symbol id="icon-heart"
          viewBox="0 0 24 24">
    <path d="M12 21.593 C 6.37 16.054..."
          fill="currentColor"/>
  </symbol>

  <symbol id="icon-star"
          viewBox="0 0 24 24">
    <polygon points="12,2 15.09,8.26..."
             fill="currentColor"/>
  </symbol>
</defs>

<!-- Stamp with <use> -->
<!-- x/y = position, width/height = size -->
<use href="#icon-heart"
     x="10" y="32"
     width="24" height="24"
     color="#e11d48"/>

<!-- Different size, same symbol -->
<use href="#icon-heart"
     x="88" y="22"
     width="44" height="44"
     color="#be185d"/>

<!-- Rotate via transform -->
<use href="#icon-arrow"
     x="10" y="68"
     width="30" height="30"
     color="#4f46e5"
     transform="rotate(90, 25, 83)"/>

<!-- CSS currentColor lets <use>
     inherit fill from parent/attribute -->
<!-- Set color="" on <use> to control
     fill="currentColor" inside symbol -->
Key Concepts
  • <symbol> — defines a reusable graphic with its own viewBox; not rendered directly
  • <use href="#id"> — instantiates the symbol; each instance is independent in the DOM
  • x, y, width, height on <use> — position and scale the symbol into its viewport
  • fill="currentColor" inside a symbol + color="…" on <use> — theming without duplicating shapes
  • transform on <use> — rotate, translate, or skew individual instances
  • Symbols are the basis of SVG sprite sheets — one hidden SVG containing all icons, used across the page
  • preserveAspectRatio on the symbol controls how the viewBox scales into the use-site viewport