Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Working with fonts

From: CSS Fundamentals

Video: Working with fonts

In this chapter, I want to spend some time going over some of the common CSS concepts that you are likely to encounter when using style sheets. While the main focus will be to provide you with a broad overview of topics, we will spend some time exploring syntax and best practices to use when authoring styles. I want to start by focusing on fonts. Controlling typography is often the first thing the designers learn to do when using CSS, and for good reason. Typography is so important to your design and what you're trying to communicate that it's just a natural starting point.

Working with fonts

In this chapter, I want to spend some time going over some of the common CSS concepts that you are likely to encounter when using style sheets. While the main focus will be to provide you with a broad overview of topics, we will spend some time exploring syntax and best practices to use when authoring styles. I want to start by focusing on fonts. Controlling typography is often the first thing the designers learn to do when using CSS, and for good reason. Typography is so important to your design and what you're trying to communicate that it's just a natural starting point.

Remember, if you don't specify a font and format your text, your content will receive the browser's default styling. I highly doubt that that's the look that you are going for. The first thing that you will need to decide when choosing a font for your site is whether you want to use the older, more widely supported system fonts or take advantage of the emerging technique of using web fonts. Let's take a moment to discuss the differences between the two. Now in the past, designers have been limited to using a small set of fonts that are preinstalled on almost every machine.

These are called system fonts, and I have no doubt that you have used them at one time or another. Fonts like Arial, Helvetica, Verdana, Times, Times New Roman, and Courier, and yes, even Comic Sans, are so common on the web that you're more likely than not to encounter at least one of them every time you go online. So, why are these fonts so popular? Well, it has very little to do with the popularity or quality of the fonts, although most of them are quite good, and everything to do with their ubiquity.

Until recently, HTML and CSS contained no mechanisms for displaying a font that wasn't already installed on the client's machine. You could certainly specify that you wanted your web pages to use Garamond, but unless the person viewing your page had Garamond installed, it would fall back to the system's default font. You can see this concept illustrated most clearly by looking at the syntax for declaring font families. Now at first glance, this may look a little odd. Here the designer seems to be asking for more than one font for all paragraphs.

In reality, what this syntax allows designers to do is to provide fallback fonts in case the first one requested isn't found on the client's system. In this case, the first choice would be Arial. If Arial wasn't installed, it would then request Helvetica. If Helvetica wasn't found, it would then request Verdana. And if in the unlikely event that one of those three fonts weren't found, it would finally ask for the system's default sans-serif font, so that at least the text would display in the style that the designer wanted.

Now is there anything wrong with that? No, actually there isn't. Many of the system fonts, like Georgia and Verdana, were designed specifically for the screen, making them very functional choices for web sites. However, recent advances to CSS and browser support now make it possible to use a much wider array of fonts. By now you've probably heard of web fonts. Web fonts is simply the term typically used to describe the technique of embedding font files in web pages using the @font-face method.

This allows web authors to use fonts without worrying about whether they're installed on the client machine or not. The CSS @font-face rule has actually been around for quite some time, but only recently has browser support, font formats, and licensing issues reach the stage where it's actually feasible to use. Web fonts typically work by having an @font-face rule, such as this one, in your styles that point to an external font resource. Now, this could be a font that you host yourself or one that's hosted through any number of recent font hosting services that have appeared to support web fonts.

Now, I know that this syntax looks a little complicated, but trust me, it's not as bad as you think. There are also plenty of online resources that can help you find fonts and even generate the syntax for you. I'll list some of those in the final chapter. If you want a deeper look into web fonts, check out my lynda.com title, Web Fonts First Look. What all this means is that when you are working with fonts in CSS, you have three basic choices: first, you could rely on the browser to supply the user's default font; second, you can specify a preferred system font and then provide fallback fonts all the way down to specifying the generic font family to use in case the client machine doesn't have the defined fonts installed; or third, you can use @font-face to supply custom fonts to the browser.

You could also use a blended approach, where you use web fonts but provide fallback system fonts to the user agent if it doesn't support web fonts. Okay, now that we have we talked little bit about some of the different ways you can use fonts with CSS, we will move on and talk about some of the options for formatting fonts, and we'll do that next.

Show transcript

This video is part of

Image for CSS Fundamentals
CSS Fundamentals

36 video lessons · 68620 viewers

James Williamson
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.


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.

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 CSS Fundamentals.

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


OK
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
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.