Add Beautiful Fonts to Your Site

Aug 5th, 2009

in Design

Embedding fonts with @font-face1

What is @font-face?

The W3C puts it like this:

The @font-face rule allows for linking to fonts that are automatically
activated when needed. This permits authors to work around the limitation of
“web-safe” fonts, allowing for consistent rendering independent of the fonts
available in a given user’s environment.

Handcrafted CSS

Handcrafted CSS

In his new book2, Dan Cederholm says:

“Initially introduced back in CSS2, but then later removed in CSS2.1 only to be added back to CSS3, @font-face is an at-rule that allows for embedding font files using CSS declarations. And oh is it simple to implement.”

In other words… you display an image in a web page by specifying a URL to fetch it from, right? You can do that with fonts too. The @font-face rule allows for linking to fonts that are automatically activated when needed.

Pros & Cons

How does it work?

  1. Download the font to your computer.
  2. Upload it to your server.
  3. Define your font family name and the file source using @font-face.

The example from the video

Before

Firefox screenshot before changes

Firefox

After

Firefox screenshot after changes

Firefox

Safari screenshot after changes

Safari

The code I used

/*Define embedded font name and source file*/
@font-face {
 font-family: Diavlo;
 src: url(fonts/DiavloMedium-Regular.otf) format("opentype");
}

/*Applies Diavlo to all headings*/
.custom h1, .custom h2, .custom h3, .custom h4, .custom h5, .custom h6 {
	font-family: Diavlo, georgia, serif;
}

Further reading

1 Star2 Stars3 Stars4 Stars5 Stars (4) Loading ... Loading ...
Share and Enjoy:
  • email
  • del.icio.us
  • Facebook
  • Digg
  • FriendFeed
  • Twitter
  • StumbleUpon
  • Technorati
  • Reddit
  • Yahoo! Buzz
  1. also referred to as web fonts []
  2. I’m loving the book by the way. []
  • robdehko
    your tutorials are great, I am having an issue with the diavlo font when I upload from the server(the ftp Filezilla) it is giving me an error-critical error then another line says status: Disconnected from server-- the site is www.HairsNotFair.com any help woulld be great
  • moditz
    Hi Fabi

    I am wanna do the same with the thesis main navigation, could you help me out?

    btw: Your tutorial style is great!

    thanks

    mo
  • mo, what are you trying to do exactly? Don't forget to leave a link to your
    site so I can take a look please. ;)
    --
    Fabi
  • moditz
    Hi Fabi

    the website is in the early building process..


    I want to add the font of our logo as main navigation. Now I manage to do
    that locally on my computer (adding the code @font face in layout.css). But
    as soon as I change anything in the design panel of thesis it resets the
    changes I've done in "layout.css". Can you help me ? (btw: I'm not a coder,
    just a player;))

    all the best

    mo
  • Great tutorials! Please keep them coming. I'm such a newbie and your tutorials are so easy for me to follow.
  • I'm happy to hear they are helping you Danielle. :)
blog comments powered by Disqus

Previous post:

Next post: