How does the font-family property work in CSS?

Jay picture Jay · Feb 20, 2011 · Viewed 7.7k times · Source

How does the font-family property work in CSS? Why is more than one font used? Isn't only one font used at a time by the browser?

Answer

Cody Gray picture Cody Gray · Feb 20, 2011

The font-family property holds several font names to provide a "fallback" system.

The browser tries each font family in the order that they are listed; if the browser does not support the first font, it tries the next font, and so on, down the list. That's why it's important that at least the last font in the list be a generic font family that is guaranteed to be universally available. There is no guarantee that the fonts you have loaded on your computer when you design the web page will be loaded on your visitor's computers—fonts are generally handled client-side, rather than server-side.

A common declaration might look like this:

font-family:Georgia,"Times New Roman",serif;

The "Georgia" font will be used if it is available. If not, the browser will attempt to fall back to "Times New Roman". If it can't find that font either, it will use a generic serif font.

For more technical information, I suggest reading the Fonts specification from the W3C.