There has been many techniques to use vector icons on web sites. From importing bitmap image files (usually transparent PNG’s), to vectorized SVG’s or even using web fonts containing symbols instead of typical characters. All of those have advantages and disadvantages, so the choice is not always easy.
Even though, using non-standard fonts (in general) has became a standard of web developement in the recent years. Displaying icons through fonts is the same as using non-standard fonts for titles and paragaphs. Times, where web designers could choose only from 5-10 different fonts, are – luckily – over.
Using icons as web fonts has many advantages:
- fonts are scalable (no quality loss with different sizes);
- no need to care about support for Retina displays;
- easy to apply CSS properties (color, gradient, shadows, etc.) without editing the icon itself;
- you can use the same icon (shape) in different sizes, colors (saves time and performance);
Nonetheless, icon fonts have also disadvantages. The biggest I see is the unreliable rendering across browsers. The problem can be demonstrated with the following screenshot:
The other disadvantage, which is also related to inconsistent rendering, is positioning. It can be tricky to position a tiny icon into center of a circle, so it looks the same in every browser.
If you want to get more deep into this, you can find many articles with pros and cons of using icons as web fonts (Ian Feather’s Article, CSS tricks, SitePoint, etc.).
OK, enough of this. Let’s create an icon font and show how to use it on a website.
II. Creating an icon font
The first thing you need to do is to make your own personal selection of icons. It’s prefered you do that for every project individually, because including all of the icons, even if not used on a project, makes the font file larger. Carrying about loading times is still crucial for the mobile experience.
All Picons icon collections come with included SVG’s of each icon. But, we also have an own icon font with 130 selected icons, if you want to jump the step of creating your own.
There is variety of free and paid tools for creating own fonts. Specialized tools such as icomoon, Fontello, etc. are free and very easy to use. We will show the steps based on comoon’s app.
Step 1: Drag & drop selected SVG’s and create a new set
Step 2: Select all the icons you wish to include in an icon font (you can select them from various sets)
Step 3: Generate the Font
Step 4: Rename all the symbols as you wish and define a unicode character for each (optional)
Step 5: Download the generated file
III. Using the icon font on a website
Your generated icon font consists of various font formats (for cross-browser compatibility) and demo files including HTML and CSS.
Step 1: Copy the CSS code in the included “style.css” to your own CSS file
The included CSS file has a predefined class for each icon, telling your browser which character in the font to use for a specific symbol. You can also apply your own CSS styles to each icon (color, shading, etc…).
Step 2: Copy the folder “fonts” to your website folder
The folder “fonts” includes your generated icon font in different formats (woff, tff, svg, eot). Be sure that the uploaded fonts are linked from the imported CSS. If placed somewhere else than “fonts/”, then correct the link direction accordingly.
src: url('fonts/thin_custom.eot?hpwvww#iefix’) format('embedded-opentype’),
Step 3: Insert the icons
An icon can be inserted with the following HTML code:
Where the class name “icon-notebook” is generated from the title you gave each icon when creating the icon font. The classes are referred to styling definitions in the included CSS file:
The styling (size, color, hover, etc) can be applied inline (inside the HTML) or to your style.css.
Your feedback (including questions) is always welcome…