How and When to Use Icon Fonts in Your Website Design
If you’re not aware, icon fonts are vector-based fonts that are filled with functional pictographs, such as characters and symbols, instead of letters and numbers. Web developers can greatly benefit from using icon fonts in website design because they are truly scalable and resolution-independent.
Because icon fonts consist of only one font file, there’s only one HTTP request. And because icon fonts are defined in graphical primitives such as circles, lines, curves, and polygons, independently of the selected output device, they can easily be transformed without losing any data.
Therefore, they don’t have to be loaded and adjusted in a separate graphics program. Instead, icon font formatting is completed by the web browser.
Let’s take a look at some of the further benefits of using icon fonts before digging into how and when to use them in your website design.
Benefits of Icon Fonts
It’s a time-consuming process for web developers to generate sprites and manually position images of different sizes. On the other hand, when you use icon fonts, you’ll save time and hassle throughout the whole development process.
Furthermore, icon fonts look fantastic on any display or screen resolution. By adopting icon fonts for your website design, there’s no need to render icons on web pages using images. So, you can avoid the problems of using images, such as the fact that they add file weight, require additional HTTP requests, and don’t scale well, by using icon fonts instead.
For instance, Bitmap images do not scale well. When you scale them up, they can lose their quality. And you can waste file size when they’re scaled down. And because each image requires an HTTP request, load times become slower.
Icon fonts don’t have such problems. They scale well and they don’t require HTTP requests for every character.
Other advantages of using icon fonts in your website design include the following:
- You can change the color easily.
- You can include shadows easily.
- Icon fonts can have transparent knockouts.
- Icon fonts have good browser support in general.
- You can style icon fonts using CSS easily; the same as with other fonts.
- Icon fonts are 100% accessible.
- Icon fonts are particularly useful for use on mobile devices where icons play a larger role.
How to Use Icon Fonts
The above benefits of icon fonts will give you a good idea of when to use them in your website design. But how do you go about using them?
The first thing you need to do is to find icon fonts to use. Flaticon’s icon fonts are some of the best to use. There are thousands available and they’re easy to edit, they’re responsive, and have high performance.
Once you have found the icon fonts you want to use, you need to know how to embed them. There are three main options available to you. You can wrap your icon in HTML, use CSS-generated content, or use the data-icon attribute.
Wrapping Icon Fonts in HTML
Wrapping icon fonts in HTML is pretty simple. In fact, for web developers, it’s as simple as it is for anyone to use an online template editor.
Using “s” in place of an icon font, and using “View Cart” in this example, you can easily wrap the character and add a class to the span, as follows:
s View Cart
And to display the icon, you can use CSS to style “.icon” so that it uses your selected icon font:
Using CSS-generated Content
Instead of including the character directly in HTML, you can use some CSS-generated content.
For instance, in this example, the span and character have been removed and the icon class has been moved to the link. Another class cart has also been added to the link:
You can then assign the icon to the icon class and use the “:before” element on the cart class in order to serve the character. And, if you want the character on the right, you can use “:after.” So, you would do this:
Using a Data-Icon Attribute
Similar to the above method, you can use a data-icon attribute, such as:
You can then add the selected font to the icon class, but create the character by referencing what’s in the data icon, as follows:
So, there you have it. You now know the basics concerning how and when to use icon fonts in your website design. But make sure you spend time looking at how to use icon fonts in more detail so that you can truly make the most of them.