Start learning with our library of video tutorials taught by experts. Get started

Web Fonts First Look
Illustration by John Hersey

The @font-face syntax


From:

Web Fonts First Look

with James Williamson

Video: The @font-face syntax

The first thing that we're going to do for our Alice in Web Fonts module is to add our self-hosted fonts to our page using the @font-face rule generated by Font Squirrel. Now Font Squirrel uses Paul Irish's bulletproof @font-face syntax for its kits. I recommend that you use it as well. Let's take a moment to go over the @font- face syntax, what it's doing for us, and then modify it based on how we are going to serve the fonts. Now after we're finished I'm going to give you a link to Paul Irish's page where you can learn even more about the technique.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Web Fonts First Look
3h 23m Appropriate for all Jan 12, 2011 Updated Dec 13, 2011

Viewers: in countries Watching now:

For this installment of the First Look series, James Williamson reviews the current implementation and future direction of web fonts: downloadable font resources that can be retrieved with the CSS @font-face declaration. The course begins with the evolution of online typography and current CSS font capabilities, and then dives into the W3C CSS Fonts Module specification, showing how to utilize web fonts, ensure cross-browser consistency, and how to use CSS3 to enhance the styling of web fonts. Font hosting services and tools such as TypeKit and the Google Fonts API are demonstrated. Exercise files accompany the course.

Topics include:
  • What are web fonts?
  • Understanding the font stack
  • Using @font-face
  • Rendering basics
  • Choosing a font hosting service
  • Downloading licensed fonts
  • Generating web fonts
  • Font sizing
  • Transforming text
  • Creating special effects with text shadows
Subjects:
Web Web Fonts
Author:
James Williamson

The @font-face syntax

The first thing that we're going to do for our Alice in Web Fonts module is to add our self-hosted fonts to our page using the @font-face rule generated by Font Squirrel. Now Font Squirrel uses Paul Irish's bulletproof @font-face syntax for its kits. I recommend that you use it as well. Let's take a moment to go over the @font- face syntax, what it's doing for us, and then modify it based on how we are going to serve the fonts. Now after we're finished I'm going to give you a link to Paul Irish's page where you can learn even more about the technique.

So here I have the stylesheet.css file open. You can find this in the 04_02 directory and it's in the webfontkit directory that we've downloaded earlier. So you'll just open up the stylesheet.css in there. The only thing it contains is the @font-face rule for us to use Junction. Now this syntax helps us to enable cross-browser compliance. So I want to take it a line at a time so you understand that syntax little bit better. Now, first thing that we do is we declare the font family.

This is the name that we're going to refer to in our styles when we want to use the fonts. So I'm actually going to change this from JunctionRegular to just Junction. You don't have to leave it the way that it is in the syntax if you can write something a little bit easier, maybe reduce the amount of typing you have to do, and still be informative as to what that is, well go ahead and do that. So I'm going to save that. Now the next thing you're going to notice is the source descriptor. Now this tells the browser where to find the fonts. So you can see that right here on line 7 in the source descriptor. Now the syntax order has almost everything to do with Internet Explorer.

Now Internet Explorer only supports EOT files or Embedded Open Type, but it tries to download everything else as well. Now by going ahead in offering the EOT, first we're going to keep Internet Explorer from choking on all of those other font formats. Now just because I guess it likes to be difficult, I'm not really sure, you'll notice in the next source descriptor we pass multiple URLs. Now that has everything to do with Internet Explorer as well. If we were to just daisy-chain all of the different formats using multiple source descriptions, Internet Explorer would still download them all.

Now we would use the EOT file, but it would still download that and that would increase a lot of overhead. So by going ahead and adding another source descriptor that has a local definition at the very beginning and then multiple URLs, which Internet Explorer doesn't support, it'll just ignore all the rest of that. But the other browsers will pick it up and use it. So that's what you want to use. Now you might also be wondering, okay, what's up with the smiley face? Well, the local property tells your computer what the font is named locally so that if it's already installed on the machine the browser will go ahead and request that instead.

Now the problem here is that the chance that you'll actually match the font name with exactly the same font at somebody else's computer is pretty low. So, to make sure the exact font that you want is used, the one that you're serving, instead of a local copy Paul recommends passing a two byte Unicode character that will never ever be used as a font name. In this case he chooses to use the smiley face and it's very lovely, but you can use your own symbol here if you'd like. So now that we know a little bit more about this and also notice that we're passing font-weight and font-style as normal so that this is the font that should be used in the default circumstances.

Bold and italic would use those if they're available. If not, the browse will handle the false bolding and the obliquing on its own. So I'm going to go ahead and copy this rule and then I'm going to open up the main.css file that's also found in the same folder in the _CSS directory. I want to go down to the line 33 where our global styles are. I'm just going to paste it right in there. Now I remember we changed the name to Junction. So as we'll refer to this font later on, we're going to use that single word Junction descriptor. If you didn't change that later on in the exercise files as I'm referring to Junction, you need to be referring to Junction regular.

So that's really a personal choice that you can go ahead and make. Now there's another thing that I need to change here. Syntax isn't always just copy paste. You'll notice that in terms of the structure of my site I have a directory for fonts, _fonts, and inside that or all of the resources that we're going to be requesting. So this path is basically thinking that the CSS file in the fonts are in the exact same folder. So I need to modify that. So in front of each of these font resources I'm going to do ../_fonts/.

So this is saying go up a directory then go into the _fonts directory, you'll find the resource. You've got to make sure that, number one, you do it inside the quotation marks and number two, you do the proper path. So ../_fonts/ and I'm just going to copy that and then paste that in front of every other resource. You'll want to make sure you get all these guys. There we go. Then I am going to save the file. So now then the only other thing that's left for me to do, go ahead and upload the main.css and then all these fonts to your server.

So I'm going to open up my FTP program here and connect. All I have to do is upload fonts and upload my CSS. If you'd like more information about the @font-face syntax that we're using, check out Paul Irish's post on bulletproof @font-face syntax which you can find on his blog at PaulIrish.com. He goes into details about the particulars and occasionally he'll update it if there's a change in browser implementations. So now we've got our @font-face rule in place and the code that we need to use, Typekit and Google Fonts, which we added earlier we can go ahead and move on to writing font family decorations using our web fonts and we're going to go ahead and do that next.

Find answers to the most frequently asked questions about Web Fonts First Look.


Expand all | Collapse all
Please wait...
Q: This course was updated on 12/13/2011. Can you tell me what's changed?
A: The movie "@font-face syntax update" was added, which explains changes to @font-face in HTML5.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Web Fonts First Look.

Return to your organization's learning portal to continue training, or close this page.


OK

Course retiring soon

Web Fonts First Look will be retired from the lynda.com library on April 24, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion. For updated training, check out Choosing and Using Web Fonts in the lynda.com Online Training Library.


Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked