You might be wondering how rendering icons with JavaScript affects performance. Well you're not the only one. We worried about this 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.
A Case for SVG Symbols
The case below is a great one for SVG Symbols – there are a bunch of the same icon repeated on the page, so you'll get a big performance boost by loading each of them only once using the step-by-step method below.
We'll define these icons as symbols: pencil, trash, and star.
<!-- Define the symbols, these are invisible on the page --><idata-fa-symbol="delete"class="fa-solid fa-trash fa-fw"></i><idata-fa-symbol="edit"class="fa-solid fa-pencil fa-fw"></i><idata-fa-symbol="favorite"class="fa-solid fa-star fa-fw"></i><!-- Use the defined symbols --><svg><usehref="#edit"></use></svg><svg><usehref="#delete"></use></svg><svg><usehref="#favorite"></use></svg>
<!-- Define the icon symbols, these are invisible on the page --><idata-fa-symbol="truck"class="fa-solid fa-truck fa-fw"></i><idata-fa-symbol="truck-bolt"class="fa-regular fa-truck-bolt fa-fw"></i><idata-fa-symbol="truck-container"class="fa-light fa-truck-container fa-fw"></i><idata-fa-symbol="truck-droplet"class="fa-thin fa-truck-droplet fa-fw"></i><idata-fa-symbol="truck-field"class="fa-duotone fa-truck-field fa-fw"></i><idata-fa-symbol="truck-flatbed"class="fa-sharp fa-solid fa-truck-flatbed fa-fw"></i><!-- Use the defined symbols --><svg><usehref="#truck"></use></svg><svg><usehref="#truck-bolt"></use></svg><svg><usehref="#truck-container"></use></svg><svg><usehref="#truck-droplet"></use></svg><svg><usehref="#truck-field"></use></svg><svg><usehref="#truck-flatbed"></use></svg>
Font Awesome Sharp requires Pro and specific versions!
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 --><idata-fa-symbol="picture-taker"class="fas fa-camera"></i><!-- Use the defined name --><svg><usehref="#picture-taker"></use></svg>
Make Sure to Add Some CSS
Advertisement
Remove ads with a Pro plan!
A subscription to a Pro-level plan will remove all third-party advertisements on fontawesome.com.
And of course Pro-level plans come with…
All 30,004 icons in Font Awesome
5 Classic styles of every icon
4 Sharp styles of every icon
A Perpetual License to use Pro
Services and tools to make easy work of using icons
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 --><idata-fa-symbol="picture-taker"class="fas fa-camera"></i><!-- Use the defined name --><svgclass="icon"><usehref="#picture-taker"></use></svg> Say Cheese!
SVG 2 removed the need for the xlink namespace, so instead of xlink:href you should use href.
However if you do need to support an older browser that requires it, it's
recommended to use both href and xlink:href. This way, when modern browsers
do eventually remove support for xlink:href things will continue working.
<!-- Name symbols with the value of data-fa-symbol --><idata-fa-symbol="picture-taker"class="fas fa-camera"></i><!-- Use the defined name --><svgclass="icon"><usehref="#picture-taker"xlink:href="#picture-taker"></use></svg> Say Cheese!