Start learning with our library of video tutorials taught by experts. Get started
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.
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.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.