Add Icons Using SVG Symbols

You can leverage the SVG Sprites technique to make repeated icons more performant on your page when using Font Awesome SVG + JS method.

You might be wondering how rendering icons with JavaScript affects performance. We worried about this quite a bit while we were developing it and even took some special measures to make sure it was as fast as we could make it.

Our testing shows that for the typical number of icons most people use on a site, the loading and rendering time for SVG+JS method is faster than Web Fonts .

# Example

See this working example on CodePen.io.

Font Awesome 6 installed and being activated in Font Explorer X on Mac OS X

# Step by Step

We'll define these icons as symbols: pencil, trash, and star.

  <!-- Define the symbols, these are invisible on the page -->
  <i data-fa-symbol="delete" class="fas fa-trash fa-fw"></i>
  <i data-fa-symbol="edit" class="fas fa-pencil fa-fw"></i>
  <i data-fa-symbol="favorite" class="fas fa-star fa-fw"></i>

  <!-- Use the defined symbols -->
  <svg><use xlink:href="#edit"></use></svg>
  <svg><use xlink:href="#delete"></use></svg>
  <svg><use xlink:href="#favorite"></use></svg>

Using data-fa-symbol informs Font Awesome SVG with JavaScript to create the symbol. The value of this attribute becomes the name.

  <!-- Name symbols with the value of data-fa-symbol -->
  <i data-fa-symbol="picture-taker" class="fas fa-camera"></i>

  <!-- Use the defined name -->
  <svg><use xlink:href="#picture-taker"></use></svg>

# Watch your CSS, Goose

One of the downsides to SVG sprites is that extra styling is necessary to make them behave. When using symbols you will need to handle this yourself.

  <!-- A quick, reasonable place to start with styling your symbols -->
  <style>
    .icon {
      width: 1em;
      height: 1em;
      vertical-align: -.125em;
    }
  </style>

  <!-- Name symbols with the value of data-fa-symbol -->
  <i data-fa-symbol="picture-taker" class="fas fa-camera"></i>

  <!-- Use the defined name -->
  <svg class="icon"><use xlink:href="#picture-taker"></use></svg> Say Cheese!

Something on your mind? We're all ears!

New icons just what you wanted? New thin style all that? Docs missing something key? Drop us a line and tell us all the good, bad and the ugly so we can make it even more awesome.

Manufacturers Protocol dictates this alpha cannot be captured. It must self-destruct.