Well, you're almost there.
The font-family rule allows you to specify the font you want to use in a particular element (technically, they're actually typefaces rather than fonts, but let's not be too pedantic). If you specify more than one font, the browser will use the first one (starting from the leftmost) that the user has installed.
But what if the user doesn't have
any of them installed? That's where
generic fonts come in. These five keywords broadly define a type of font:
serif - A font with serifs (the little sticky out bits on the ends of lines), e.g. Times New Roman
sans-serif - A font without serifs, e.g. Arial
monospace - A font where all characters are the same width, commonly used to display computer code, e.g. Courier
cursive - A font which looks like handwriting, e.g. Comic Sans
fantasy - A fancy or decorative font used in titles, e.g. Algerian
When you specify one of these, you're asking the browser to use whichever font of that type is available to it. So if I say
Code:
.foo { font-family: Helvetica, "Gill Sans MS", sans-serif; }
I'm saying "elements of class
foo should be rendered in Helvetica if you have it, failing that use Gill Sans MS, and if you don't have either of them use whatever sans-serif font you do have". Normally, you'll use the generic font that most matches the specific font(s) that you asked for, but you don't have to do so. This is perfectly valid code:
Code:
.bar { font-family: Helvetica, "Gill Sans MS", serif; }
As you can never be 100% sure what fonts all your user will have, you should always specify a generic font at the end of each font-family rule.
-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd