Webfont Icons: an Alternative to Images

Share this article

Let’s be honest, creating dozens of tiny icons in a graphics package isn’t fun. Even when you’ve gathered a decent set, you end up managing dozens of tiny files or creating image sprites and slicing them in CSS. Fortunately, HTML5 provides us with another option: webfonts. A font set can contain graphical icons and character sets. Wingdings is the most well known but free fonts such as Iconic
can be more useful and provide example HTML and CSS code. View the webfont icon demonstration page… Once you’ve found or created a suitable font, you’ll need to convert it to a number of formats to ensure good cross-browser compatibility. The @Font-Face Generator at fontsquirrel.com does the hard work for you and supplies a ZIP file containing all the fonts and CSS code. The font is then imported at the top of your CSS file, e.g.

@font-face {
	font-family: "IconicStroke";
	src: url("iconic_stroke.eot");
	src: url("iconic_stroke.woff") format("woff"), 
	url("iconic_stroke.ttf") format("truetype"), 
	url("iconic_stroke.otf") format("opentype"), 
	url("iconic_stroke.svg#iconic") format("svg");
}
It’s possible to add icon characters to your HTML file, such as using an ‘r’ for Iconic’s RSS icon. However, that may confuse people using screen readers so CSS pseudo elements are a safer option, e.g. Your HTML:

<a href="rss.xml" class="rss">RSS Feed</a>
Your CSS:

.rss:before
{
	font-family: "IconicStroke";
	content: "r";
}

The Advantages of Webfont Icons

Webfonts can be an ideal alternative to graphics:
  • fonts can be scaled to any size, use any color and have CSS effects applied
  • webfonts offer good cross-browser compatibility and even work in IE6
  • a single font file can be more efficient than multiple images

The Disadvantages of Webfont Icons

Webfonts may not always be appropriate:
  • font characters are single-color (although CSS3 effects can help)
  • generating fonts is not as easy as PNGs or SVGs
  • image file sizes will be smaller if you only require a few icons.
Overall, there’s little to dislike about webfont icons and they could cut development time. Have you used them in any of your projects? View the webfont icon demonstration page…

Frequently Asked Questions about Webfont Icons

What are webfont icons and why are they important?

Webfont icons are scalable vector graphics that can be customized with CSS in terms of size, color, drop shadow, or anything else that can be done with CSS. They are important because they allow for a lot of flexibility and customization, and they can be scaled to any size without losing quality. This makes them ideal for responsive web design, where the size of the screen can vary greatly.

How do I use webfont icons on my website?

To use webfont icons on your website, you first need to include the webfont file in your project. This can be done by downloading the file and hosting it on your own server, or by linking to it directly from a CDN. Once the file is included, you can use the icons by adding the appropriate CSS classes to your HTML elements.

Can I create my own webfont icons?

Yes, you can create your own webfont icons. There are several tools available online that allow you to convert vector graphics into webfont files. This can be a great way to create a unique look and feel for your website, and to ensure that your icons perfectly match your brand.

What are the advantages of using webfont icons over traditional image icons?

There are several advantages to using webfont icons over traditional image icons. Firstly, webfont icons are vector graphics, which means they can be scaled to any size without losing quality. Secondly, they can be customized with CSS, allowing for a lot of flexibility in terms of color, size, and other properties. Finally, webfont icons are typically smaller in file size than image icons, which can help to improve the load time of your website.

Are there any disadvantages to using webfont icons?

While webfont icons offer many advantages, there are also a few potential disadvantages to consider. One potential issue is compatibility, as not all browsers support webfont icons. However, this is becoming less of an issue as browser support improves. Another potential disadvantage is that creating your own webfont icons can be a bit more complex than simply using image icons.

How do I choose the right webfont icons for my website?

Choosing the right webfont icons for your website depends on a few factors. Firstly, you should consider the style and branding of your website. The icons you choose should match the overall look and feel of your site. Secondly, you should consider the functionality of the icons. Make sure to choose icons that clearly represent the action or content they are associated with.

Can I use webfont icons in email?

Yes, you can use webfont icons in email. However, it’s important to note that not all email clients support webfont icons. Therefore, it’s a good idea to provide a fallback option, such as a traditional image icon, for those clients that don’t support webfont icons.

How do I ensure that my webfont icons are accessible?

To ensure that your webfont icons are accessible, it’s important to provide alternative text for each icon. This can be done using the “alt” attribute in HTML. This text will be read by screen readers, allowing users with visual impairments to understand the content of the icon.

Can I use webfont icons with WordPress?

Yes, you can use webfont icons with WordPress. There are several plugins available that make it easy to add webfont icons to your WordPress site. Alternatively, you can manually add the webfont file to your theme’s directory and include it in your CSS.

Are there any free resources for webfont icons?

Yes, there are many free resources for webfont icons available online. Websites like Font Awesome, Google Fonts, and Iconmonstr offer a wide range of free webfont icons that you can use in your projects.

Craig BucklerCraig Buckler
View Author

Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.

CSS3graphicsHTML5 Dev Centericonswebfonts
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form