MechanisM
MechanisM

Reputation: 906

Does icons inside font good for site?

I wanna create special font containing only icons. and for each letter will be diffirent icon. I want to embed this font in css. and use like this if i need some icon:

<a class="icon">f</a>

and css

<link href='http://fonts.mysite.com/css?family=MyFontWithIcons' rel='stylesheet' type='text/css'>

which contains:

@media screen {
@font-face {
  font-family: 'MyFontWithIcons';
  font-style: normal;
  font-weight: normal;
  src: local('MyFontWithIcons'), url('http://fonts.mysite.com/font?MyFontWithIcons') format('truetype');
}
}

and to show icons with icon class:

.icon {font-family: 'MyFontWithIcons'; }

And letter "f" will be replaced with icon inside font which located on the place of f letter. and css works with font and replacing f with icon inside font. I think it's good idea or not? font file is less in size than lots of image icons. and also with this technique I can use diffirent font colors = diffirent icon colors? sizes and so on. So, it's good idea or not?

Upvotes: 3

Views: 410

Answers (4)

danyamachine
danyamachine

Reputation: 1918

All the other answers focus on the downsides. I am, personally, a big fan of using icon fonts. Here are some good reasons to use an icon font:

  1. You can seamlessly use icons inline with text. If you include an icon inside of a block of text, it will inherit the font size and color of its parent, and will be aligned with the accompanying text's baseline.
  2. you can change the color of icon dynamically using css, without having to create and upload additional image files and use js to manipulated the markup. this means that a) you are keeping style determinations where they belong, i.e. in your stylesheets and b) you can simply and easily make your icon colors contextual (e.g. all icons inside headers are white, or else they are black) and themable (e.g. all icons are white if body has class dark-theme, and all icons are pink if body has class tropical-theme)
  3. the icon can easily be scaled without using additional bandwidth (as it would if you were increasing the size of the image file), without having to create and upload additional image files. corollary: you don't have to worry about different screen resolutions and don't need to make any allowances for retina, etc.
  4. your font file will likely have a smaller file size than your image files would so, again, save on bandwidth.
  5. if you use a font generator such as fontello, your collection of icons will automatically be catalogued for you and your designers to scrutinize, in a demo file. in addition, fontello has an API so your font generation can be managed automatically as part of your build process.

Upvotes: 0

ssokolow
ssokolow

Reputation: 15355

The problem with using a custom font for icons is that you've got no backup plan if:

  • Your user's browser is too old to support @font-face
  • The user agent isn't your traditional browser (eg. Screen readers for the blind, search engines, HTML-to-text converters, etc.)
  • The user copy-pastes the text containing the "icon" into something that discards rich formatting information or doesn't have the font in question.
  • The user agent will never support @font-face (Eg. Textual web browsers like Lynx, Links2, and ELinks for Unix/Linux)
  • The user is behind a corporate proxy that discards or mangles headers that your browser demands before displaying custom fonts. (more common than you think)
  • The user is running NoScript with the default font-blocking behaviour enabled to protect against 0-day exploits in the font engine.

Images provide the alt attribute for just this reason.

However, if you're going to use a font for icons, make sure you store your glyphs in a Unicode Private Use Area. That'll mitigate the problem a bit by ensuring there's probably no conflict (Companies can and do sometimes use PUA glyphs to store custom data) and, if they're coded smartly, screen readers could know to gracefully ignore PUA glyphs.

As for implementing a fallback, I'd suggest using Modernizr (specifically, Modernizr.fontface) to test for support.

Upvotes: 6

Moin Zaman
Moin Zaman

Reputation: 25465

  • @font-face is not supported uniformly across browsers. Its a bit of a task to cater to all browsers esp. if including IE6
  • Accessibility: screen readers won't read icons, they would still see an 'f' and not an icon
  • You would need some fallback to degrade gracefully

Upvotes: 0

Jouke van der Maas
Jouke van der Maas

Reputation: 4338

It's a good idea but it doesn't work in all browsers (yet). Also, it only works with 2 color images (black and transparent), which makes it rather limited. For people with text browsers or text to speech software, it won't make any sense. It's not really 'semantic', because the <img>-tag was meant for images. Using fonts for that won't make any sense from a html-only perspective. It also clutters your css.

So that's a lot of bad things just for a little bit less bandwith; I wouldn't bother.

Upvotes: 0

Related Questions