A little over a week ago, Wayne Helman posted an article proposing the use of @font-face for displaying icons. The article was well-received, but I was honestly expecting more excitement around this idea. From my view, this now seems like the way to set icons in a site. I feel strongly about the potential of this method, so I thought I would take the time to generate a font set for Iconic and to talk about why we should all be using this method for displaying icons.
Look Ma, No Images
Before I go into details, if this method is new to you, here is a simple demo of font-embedded icons. The basic idea is to generate a font containing your icons (much like wingding font sets), embedding that font using the @font-face CSS rule and taking advantage of the :before selector and content rule to inject a character bound to a specific icon.
- Home
- Plus
- Minus
- Window
- Dial
- Lightbulb
- Link
- Image
- Article
- Spin
- Map Pin
- Pin
- Denied
- Calendar
- Bolt
- Clock
- Book
- Tag
- Heart
- Info
- Chat
- Key
- Unlocked
- Locked
- Phone
- Box
- Pencil
- Comment
- Trash
- User
- Volume
- Mute
- Cog
- Check
- Beaker
This demo is a simple list with a tags given specific classes for specific icons. Wayne Helman’s method was structured in a slightly different manner, but the general concept is the same. This method is surprisingly backwards compatible and low maintenance.
Pros and Cons of Font-Embedded Icons
Like pretty much everything in life, tradeoffs do exist with this method. I know for a fact that I will be implementing this method on my site, but I am certain I will not be using it for all my projects. Below is a basic breakdown of advantages and disadvantages.
Advantages
- Potentially far less HTTP requests
- Downloading 100 small files can be far slower than downloading one large file. Depending on the individual situation, this could result in a faster page load.
- One icon, infinite sizes
- Vector icons mean vector scaling. No more icon_8×8.png, icon_16×16.png, icon_24×24.png, etc.
- Cleaner system for icon management
- Managing icons in multiple colors and sizes can be a serious pain. With font-based icons, all the color/size variations you need are in just one file.
- Switching your icons in one line of CSS
- With all the talk about TypeKit and how easy it is to embed fonts, the same could soon be the case for icons. No more batch-replace of image references.
- CSS3 transitions open interesting doors
- Transitions, effects and transforms are all open game. More on that further down in the article.
Disadvantages
- Fonts can be large in size
- A complex font can easily be 90Kb. That can be a hard pill to swallow if you simply want to use one specific icon.
- No standards in place for key-binding
- If you are under the opinion that TypeKit should offer icon sets as embeddable fonts, there needs to be some standards in place for what icons are in an icon set and what keys they are bound to. Otherwise switching icon sets could display unexpected icons.
- Potential for tag-bloat
- After playing around with embedding icons, it became clear that improper implementations could easily lead to ugly markup.
- Multi-colored icons are a no-go
- If you want to embed icons like famfamfam with various colors/shades, you’re screwed. CSS3 can give you some simple gradients, but beyond that this method is just not going to work.
Implementation
The following is a quick rundown on how I implemented the demo at the beginning of the article. I am not presuming that my method is the best or even a proper method at all. I would really enjoy seeing how others think the HTML/CSS should look for this use case.
The CSS is cut and dry. Most of us have seen this plenty of times. Snook goes into far more detail if you are interested.
@font-face {
font-family: 'IconicStroke';
src: url("iconic_stroke.eot");
src: local('IconicStroke'),
url("iconic_stroke.svg#iconic") format('svg'),
url("iconic_stroke.otf") format('opentype');
}
I apply a class (perhaps too specifically) named ‘iconic’ for wherever I want to use the font-embedded icon. I set the display to inline-block to allow for CSS3 transformations.
.iconic {
display:inline-block;
font-family: "IconicStroke";
}
I then add rules for each icon where I use the content rule to inject the ASCII character bound to that specific icon.
.iconic.home:before {
content: '!';
}
Lastly, in the HTML, I use an a tag, since it could also potentially be used as an anchor destination in certain situations. The use of the blank a tag is not necessary, but it seemed like solid method to create a tag exclusively for the icon when it needed specific styling.
<a name='home' class='iconic home'></a> Home
Using CSS3 With Font-Embedded Icons
Integrating CSS3 into font-embedded icons is the difference between this method and using images for icons becomes apparent. Below is a simple, yet not-so-aesthetic example of what can be done to a font-embedded icon with CSS3. This used to be the sort of thing that was completely relegated to Flash. With vector icons, we have full scaling flexibility — something that is far more powerful than we typically think. Note, you must be viewing this in Safari or Chrome to see some of the effects and the transitions.
Roll over this text to see transition
Below is the code used to implement this. No Javascript was needed for this.
.iconic {
display:inline-block;
font-family: "IconicStroke";
text-shadow: 0px 0px 2px rgba(0,0,0,.33);
-webkit-transform: rotate(0deg) scale(1);
-moz-transform: rotate(0deg);
-webkit-mask-image: -webkit-gradient(linear,
left top,
left bottom,
from(rgba(0,0,0,.5)),
to(rgba(0,0,0,1)));
-webkit-transition: all .3s ease-in-out;
cursor: default;
padding:10px 0 10px 10px;
}
.iconic:hover {
-webkit-transform: rotate(-10deg) scale(1.3);
-moz-transform: rotate(-10deg) scale(1.3);
text-shadow: 0px 0px 4px rgba(0,0,0,.5);
color:#c00 !important;
}
This Concept is Worthwhile
There are many CSS techniques that come around which ultimately end up being gimmicky — this is not one of them. If implemented appropriately, this method could allow for more creative flexibility, all while using less bandwidth. I have taken the time to compile many of the icons in Iconic into a typeface in addition to creating a starter CSS file. This should give anyone who is interested in implementing this method enough to be on their way. I look forward to making the switch on my site and hope to see others do the same.



The Discussion
26 Comments on “Font-Embedding Icons: This Is a Big Deal”Dwayne Anderson
5.05.2010 6:51 amWell done, sir. Well done… very excited to try this out…
Ed
5.05.2010 10:30 amBrilliant idea, when will the iconic font be coming out? Really like the rollover, which BTW, works in Firefox as well.
Ed
5.05.2010 10:56 amIn firefox there is a noticeable transition from non-icon to icon
Michael Minter
7.05.2010 8:42 amThis is a great idea. Thanks for sharing!
Karlo Espiritu
7.05.2010 9:32 amNice work and thanks for this info, I might probably use this technique in a future project. I think this is very useful for administration interfaces.
Another Ed.
7.05.2010 9:35 amDoesnt work in Firefox on mac.
Scott Corgan
7.05.2010 9:46 amThat is epic, but sad. It’s sad we have to hack the tools we have to just to do stuff efficiently!
Wayne Helman
7.05.2010 10:05 amElegantly put. For those concerned about certain browsers transitioning from text to icon, the method I’ve been deploying is to set opacity on the element to 0 and post-load, fade the icon in with your favourite JavaScript API. Just be certain to have the icon’s element defined as some kind of block with a width and height, so the browser can determine layout issues during rendering.
Martin
7.05.2010 10:45 amActually i read the article on tutsplus too and thought just as you.
However if you think about it it’s just not that good.
Some of my points:
1. You don’t change the size of an icon normally. (Do you?)
2. HTTP-Requests can be saved with sprites.
3. It’s harder to add new icons to the set ( at least for me it would. )
4. Filesize is little smaller with pngs. (look at #1)
5. Semantics / Accessability
I think that’s all.
Further discussion is appreciated. (@mklappstuhl)
- Martin
Esteban Mata
7.05.2010 10:51 amIncredible! This is pure genius!!!
I think I’m gonna use this on my new site.
I was playing around and made a slight change:
I wasn’t happy with the extra code in this line:
Home
as I see no real use of an “a” tag everytime I need an icon… so I thought about using the :first-letter pseudo code.
This is my final CSS code:
.iconic {
display:inline-block;
}
.iconic:first-letter {
font-family: “IconicStroke”;
}
.iconic.home:before {
content: ‘!’;
}
and the HTML:
Home
and still works for me
mike
7.05.2010 11:04 amI dunno, I don’t really see this as big of a deal as you. I don’t use a lot of icons in my designs, when I do, I only use a few. It is hard to imagine a design that needed enough to justify making a font for all of the icons.
Onur
7.05.2010 1:55 pmThis is a great idea. Thanks for sharing!
Vincent Flanders
7.05.2010 3:36 pmSteve Souders has an excellent overview of the problems with @font-face and it has links to other discussions. It’s at http://www.stevesouders.com/blog/2009/10/13/font-face-and-performance/
Vincent Beneche
7.05.2010 4:02 pmThis is amazing ! I’m just afraid by the lack of compatibility with browsers… but it foresees an aspect of great future of webedsign and interaction design…
Ed
7.05.2010 4:08 pmAccessibility and file size. At the moment I just don’t see it as workable solution. I like the concept and cheer on smart folks continuing to make it better. Thanks for working on this and I’ll be sure to keep checking in on its progress.
iPad Links: Friday, May 7, 2010 « Mike Cane's iPad Test
7.05.2010 5:18 pm[...] simple things that browser developers can do today to make HTML5 Apps real HTML5 Text Path demo Font-Embedding Icons: This Is a Big Deal Ajax Style Loading Animation in CSS3 ( no Images ) Modern CSS Layouts, Part 2: The Essential [...]
Ed (the first one)
8.05.2010 2:12 amWorks in firefox on my mac but I had to disable NoScript for this site.
Joshua Schoenaker » Font-Embedding Icons: This Is a Big Deal ✔ Scriptie over webtypografie
8.05.2010 3:25 am[...] bijvoorbeeld ook aan de Wingdings waar we vroeger allemaal mee geprutst hebben met Microsoft Word. SomeRandomDude legt uit waarom dit vanaf nu al alle icoontjes als afbeeldingen zou moeten [...]
links for 2010-05-08 « Mandarine
8.05.2010 9:05 pm[...] Font-Embedding Icons: This Is a Big Deal The basic idea is to generate a font containing your icons (much like wingding font sets), embedding that font using the @font-face CSS rule and taking advantage of the :before selector and content rule to inject a character bound to a specific icon. (tags: @font-face webdev fonts icons) [...]
Veckans länktips – 2010-05-09 | lillbra.se
9.05.2010 7:23 am[...] Font-Embedding Icons – Some Random Dude Använd ett typsnitt istället för bilder för att skapa ikoner. (taggar: @font-face css3 typeface design icon fonts ) [...]
Embedding Icons with CSS3 | Design Reviver
13.05.2010 5:40 am[...] Font-Embedding Icons: This Is a Big Deal [...]
Pattern Inc » Embedding Icons with CSS3
13.05.2010 6:00 am[...] Font-Embedding Icons: This Is a Big Deal [...]
????????????? @font-face ? ???????? ?????? « Awebdesign's Blog
17.05.2010 7:42 pm[...] ????????????? @font-face ? ???????? ?????? ?????????? ? ?????? ??????? ???? / Best World Designs ????????????? awebdesign ?? 18.05.2010 ?????????? ???? ????????????? ?????? ? ???????? ?????? ????? ?? ????? Some Random Dude. [...]
John Faulds
19.05.2010 4:47 amDo screenreaders read out the generated content? That would be my main concern about this because it could affect the meaning of the text.
lirik
17.06.2010 9:09 amgreat post.. thanks for sharing
Jon B
18.06.2010 11:16 amIt would be cool if your font was ‘monospaced’ so each ocon occupied the same horizontal space – in this way the text in a list with prefixed icons would line up a lot nicer I think :)