CSS3 Embedding @font-face

css3 embed font face

Want to get away from ‘Web Safe’ fonts for some attractive headers AND do it without using an image? Use CSS 3 and embed a font-face!

NOTE: This article uses font file stored online and your browser may run slow or attempt to crash… sorry!

@font-face is not strictly speaking ‘CSS3′; it was originally born in CSS 2 and although not appearing in CSS 2.1, CSS 3 is attempting to bring it into the standards.

In order to use a font, we first must call it using the ‘@font-face’ attribute and this must be done for each individual font we wish to use. Although I’m sure you have a few, you can download some fonts to experiment with here, at dafont.com.

CSS 3 Embedded Font Face

HELLO CSS 3 WORLD!

The above header uses the SketchRockwell font with the following CSS 3 applied to it.

  1. CSS 3 Font Embed (Example I)
  2. @font-face {
  3.   font-family: SketchRockwell;
  4.   src: url(‘SketchRockwell.ttf’);
  5. }
  6. .my_CSS3_class {
  7.   font-family: SketchRockwell;
  8.   font-size: 3.2em;
  9. }

CSS3 can render type using several font formats: “truetype” (ttf), “opentype” (otf), “embedded-opentype” (eot) and “scalable-vector-graphic” (svg,svgz).

HELLO CSS 3 WORLD!

We can also apply additional effects such as a Text Shadow.

  1. CSS 3 Font Embed (Example II)
  2. @font-face {
  3.   font-family: SketchRockwell;
  4.   src: url(‘SketchRockwell.ttf’);
  5. }
  6. .my_CSS3_class {
  7.   font-family: SketchRockwell;
  8.   font-size: 3.2em;
  9.   text-shadow: 3px 3px 7px #111;
  10. }

NOTE: For some reason, using both @font-face and text-shadow will cause problems in Google Chrome. The reason IE has been given a ‘?’ next to it for the @font-face attribute, is because it will work using the popular .eot font file…

An example for those on alternative browsers, not seeing the embedded font..

 

The Zen Elements CSS3 Series

Thank you for reading!
@zenelements // Alex

Like this article?

Subscribe to our rss, follow our tweets or please help us spread the work & share this with your friends!

Thank you for all your support; have a cookie!

44 Comments on “CSS3 Embedding @font-face”

  1. Marylin 19.01.2009 at 12:06 am

    Another good post in your series, Alex! Also, since you asked for it… *cuddles the post affectionately* ;)

  2. Zen Elements 19.01.2009 at 12:17 am

    I was being hypothetical! I’m sure it liked it though, thank you and I’m glad you enjoyed the post

  3. mini 19.01.2009 at 11:21 am

    Opera 10a1, build 1229 presents it properly.

  4. Zen Elements 19.01.2009 at 6:40 pm

    Ah, brilliant. Thank you for the heads up on that :)

  5. Sonali Agrawal 19.01.2009 at 10:11 pm

    Wonderful post, no doubt, but you have mentioned that it works with Firefox 3.0.5; which I am using….and it doesn’t seem to work. Works on Safari very well.

  6. Zen Elements 20.01.2009 at 10:56 am

    Hi Sonali. I mentioned in this post that FireFox 3.0.5 is incompabitable with the CSS2/3′s @font-embed command.
    There was a statement afterwards however suggesting it may be compatible with FireFox 3.1alpha. This I have edited to remove any confusion.

    Thanks for the feed back.

  7. Ancient Wrath 26.01.2009 at 10:30 am

    Why don’t they make this a standard for browsers? It seems WAY better than sIFR…

  8. Andrew 08.02.2009 at 7:28 am

    The good news is that @font-face support is spreading, by mid 2009 most browsers should work. Both Firefox betas and the new Opera alpha support it, leaving only IE with a broken implementation.

    Microsoft’s insistence to only support their brain-dead EOT format fonts means that providing universally viewable fonts is a real pain in the neck (the fact that Microsoft’s own tools for creating EOT files doesn’t work is only part of the problem.)

  9. Zen Elements 09.02.2009 at 10:05 am

    @Andrew | Support is growing across all browsers, still it is at quite a slow pace. The more it is spoken of though, through posts, news groups, social media / networking, etc… the more it is noted by browsers to develop for it, giving it a little more of a push. SO, hopefully by 2025 everything will be supported entirely.. :P

  10. Scott Benton 06.05.2009 at 10:16 pm

    Thanks for the article. As a designer who works in multiple media, the prospect of using embedded fonts to me is simply awesome. For established companies with graphic standards, every time a web page loads they’re either breaking their own standards, or using images or Flash to present fonts that are within spec. The former approach is a shame for designers and companies who work very hard to present a consistent brand to their consumers. The latter approach chooses brand over equally important usability and web standards. Coming from the print world, to suddenly not be able to present my body copy in a chosen font was a big adjustment for me. I would love the opportunity to forget that limitation.

  11. 9swords 27.05.2009 at 7:06 am

    I am only having partial success with the @font-face property. It really depends on which browser you use. I just installed flock 2.5 and ran it through the css selectors test, pretty good :)
    I have every beta browser installed now, the slowest is Opera Alpha.
    It takes forever with images :Þ Thanks for this great post. I think i have read your entire site now, that’s why i decided to leave a comment.

  12. Pascal 15.07.2009 at 1:12 am

    FireFox 3.5 support it.

  13. Zen Elements 15.07.2009 at 8:17 am

    @Pascal | it has unfortunately been a little time since I’ve had the time to run through and update the available browser support for CSS3 but thank you for highlighting this. Helps a lot! =]

  14. FreelancerCrowd 27.07.2009 at 10:37 am

    The future of web typography seems a bit brighter :)

  15. rigel 06.01.2010 at 2:37 pm

    It works on FF 3.5/ IE 7/ IE 8! I just tested this and I’m certainly going to use it in my project.

  16. Nicole 02.02.2010 at 9:23 am

    Great article. I might use the embed font, but actually that’s the only one you can use, as most of the others are just supported in one or two browsers. It’s just sad, things can’t work in all browsers….

  17. urho 02.02.2010 at 10:05 am

    This works fine with my Google Chrome 4.0.302.2 dev on Arch Linux.

  18. Zen Elements 02.02.2010 at 11:29 am

    @urho – Thank you for pointing this out; it has been a while now since these CSS3 articles have been written and I’m afraid browser compatability has altered in a few areas. Along with a new site design (coming soon…) I will be updating the blog and the content therein also. I’ll be sure to re-test browsers and so will keep this in mind too. Thanks again.

  19. Ben 16.02.2010 at 3:11 pm

    I’m looking at Impact. Looks like your font isn’t being loaded.

  20. Zen Elements 16.02.2010 at 3:32 pm

    Thank you for pointing that out! I must not have redirected the stylesheet since moving host & domain. Thank you again and hope you liked the post, besides that tiny slip-up! =]

  21. Mathias Lorenzen 02.03.2010 at 12:17 am

    Chrome 4 supports this entirely.

  22. ahmad ali 03.03.2010 at 6:54 am

    why on my IE7 the font not show ?? can you help me

  23. Ram Siddiki 11.03.2010 at 5:26 pm

    Great post. Thanks. But I just confused on “Current Browser Support (Tested, Jan 2009)” section. It is not clear which browser is supported. If you use a “cross” and “tick” icon for those section will be much visualized for readers.

  24. Brian 02.04.2010 at 8:35 pm

    Hi, the 2nd demo(apply shadow effect) is not showing on Chrome(ver 4.1.249.1045)…

  25. Zen Elements 03.04.2010 at 10:13 am

    Hi Brian and thank you for posting; I’ve very recently (silly hours of this morning) updated things all through the CSS3 Series including article content and providing a new shiny compatibility check too. I hope the shadow is displaying correctly for you now though as in testing it appeared and the text-shadow is supported in Chrome.

  26. Brian 03.04.2010 at 8:34 pm

    Hi Alex, thanks for reply :)

    Both text-shadow and font-face are supported in Chrome, however, if apply both 2 effects together, Chrome won’t display the text.

    Please view this screen cut
    http://img69.imageshack.us/img69/41/20100404040858.jpg , the embedded font with shadow effect is not showing.

  27. Creative59 12.06.2010 at 8:50 am

    It Seems not to be working ,i tried the same code and uploaded the font to the website !
    but it doesn’t work unless i have the font installed in my PC but for your website i don’t have the fonts that u use installed and i still can see them ,…. what’s wrong ?? do i have to have the fonts installed in my PC or shouldn’t I ???

  28. Zen Elements 12.06.2010 at 9:41 am

    @Creative59: You shouldn’t need to have the font installed on your computer for this to work, so a quick question or two:
    What CSS & Markup are you using?
    What font file are you trying to use in your own example?

    If you have your (non)working example up online somewhere, I’d be happy to take a look at it for you.

    Alex / @ZenElements

  29. Creative59 14.06.2010 at 8:21 pm

    I Managed to do it thnx man i used the @font-Face kit and i copied the code ! from that website
    http://www.fontsquirrel.com/fontfacedemo/WC-RoughTrad

  30. Adie 16.06.2010 at 6:19 pm

    Nice post.

    Great series as well

  31. Designer 26.08.2010 at 12:05 pm

    Thank you for this post!

  32. leandro 30.08.2010 at 4:59 pm

    Very good!

    This will be very useful.

    tks.

  33. mcalex 17.09.2010 at 5:34 pm

    cool post, cheers

    ultra-pedantic point: in the first demo, you call the font SketchRockell when it should be SketchRockwell. ‘The above header …’

    once again, good job

  34. Zen Elements 17.09.2010 at 8:38 pm

    @mcalex – thank you for being ultra-pedantic and noticing this – being rather pernickety myself, can’t believe I missed it! I’m glad you liked the tutorial and hope you got something from it.

  35. boo 28.09.2010 at 9:23 am

    Now, we can use any beautifull font face for our site… nice article, but still cant be implemented in IE 6… :(

  36. St3vi3 27.10.2010 at 2:09 pm

    as browser compatibility is limited – i guess we won’t be saying goodbye to cufonized fonts right away then?

  37. Khay 18.11.2010 at 1:54 pm

    Yay! This is really awesome! ^^
    But where can I get the URL of the font I want to use? =)
    Thank you!

  38. SEO High Wycombe 15.12.2010 at 12:14 am

    Its great no longer having to compromise good SEO content when pushing the boundaries of website design!

  39. webdirector 24.01.2011 at 9:54 pm

    Let me point out an article in order to implement without any bugs in all browsers (Internet Explorer version 5 or up to Opera, passing through all versions of Safari, Chrome and Firefox) the rule of @ font-face. State of the art have been fixed all the problems of rendering in IE (double rule) and WebKit to render the characters in bold type.
    http://www.hightechware.it/sharedtip.php?id=9
    Happy reading!

  40. Joshua Karthik 15.03.2011 at 5:04 pm

    I think you’re missing single quotes around the font-family name. Otherwise, an excellent post! Thank you.

  41. evolve branding 08.04.2011 at 10:52 am

    great post!!! will help on my workwear site.

  42. Tony Patchen 09.10.2011 at 8:38 pm

    Wonderful website. A lot of useful information here. I am sending it to several friends ans additionally sharing in delicious. And naturally, thanks for your effort!

  43. Design Loud 16.03.2012 at 6:36 pm

    I have used this successfully on my site, and let me tell you it solves a TON of problems including some big SEO hassles. As old as this post is, it’s still relevant so thanks for keeping it up!

  44. marvin m. 01.09.2012 at 5:26 pm

    I’m very intrigued about the text shadow, I’ll try on that.

 

Leave a Reply

(required; who are you?)

(required; we'll keep it safe!)

(optional; promote your site!)