is one of several CSS at-rules, like
. At-rules are ways of encapsulating several rules together in a declaration to serve as instructions to the browser’s CSS processor.
To include fonts using
, you have to:1.
load the font file onto your servers in a variety of formats to support all the different browsers2.
name, describe, and link to that font in an @font-face rule3.
include the font’s name in a font-family property value, just as you would for system fonts
The font family and source are required, but the weight and style are optional.
For every font you have to include a separate at-rule for each variation of the font—regular, thin, thick, italic, black, and so on.
part of the
at-rule declaration is slightly different from the font-family property with which you’re already familiar. In this case, we’re declaring a name for our font, rather than assigning a font with a given name to an element.
Declaring Font Sources
The src property can take several formats. Additionally, you can declare more than one source.
src: url('../fonts/League_Gothic-webfont.eot') format('eot'),
Tip: It is always wise to use the real font name. It will help you to keep your style sheet understandable.
The first src defines the URL of the .eot file, which is necessary for compatibility with Internet Explorer (versions 5 through 9).
The successive src attributes are needed to guarantee compatibility with all modern desktop and mobile browsers. The .WOFF format is used by Firefox, while the .TTF format is used by the browsers based on WebKit.
Making the font work
Rename the font defined with the attribute font-family inside your style sheet—for example, on the tag
font: 14px MuseoSans, "Helvetica Neue", Arial, sans-serif;