The font-family
CSS property lets you specify a prioritized list of font family names and/or generic family names for the selected element. Values are separated by a comma to indicate that they are alternatives. The browser will select the first font on the list that is installed on the computer or that can be downloaded using a @font-face
at-rule.
Web authors should always add at least one generic family in a font-family list, since there's no guarantee that a specific font is installed on the computer or can be downloaded using a @font-face
at-rule. The generic family lets the browser select an acceptable fallback font when needed.
It is often convenient to use the shorthand property font
to set font-size
and other font related properties all at once.
font-family
property specifies a list of fonts, from highest priority to lowest. Font selection does not simply stop at the first font named in the list that is on the user's system. Rather, font selection is done one character at a time, so that if an available font does not have a glyph that can display a character needed, the later available fonts are tried. However, this doesn't work in Internet Explorer 6 or earlier.Initial value | depends on user agent |
---|---|
Applies to | all elements. It also applies to ::first-letter and ::first-line . |
Inherited | yes |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
/* A font family name and a generic family name */ font-family: Gill Sans Extrabold, sans-serif; font-family: "Goudy Bookletter 1911", sans-serif; /* A generic family name only */ font-family: serif; font-family: sans-serif; font-family: monospace; font-family: cursive; font-family: fantasy; /* Global values */ font-family: inherit; font-family: initial; font-family: unset;
<family-name>
<generic-name>
Generic font families are a fallback mechanism, a means of preserving some of the style sheet author's intent when none of the specified fonts are available. Generic family names are keywords and must not be quoted. A generic font family should be the last item in the list of font family names. The following keywords are defined:
serif
sans-serif
monospace
cursive
fantasy
Font family names must either be given quoted as strings, or unquoted as a sequence of one or more identifiers. This means that punctuation characters and digits at the start of each token must be escaped in unquoted font family names.
For example, the following declarations are valid:
font-family: Gill Sans Extrabold, sans-serif; font-family: "Goudy Bookletter 1911", sans-serif;
The following declarations are invalid:
font-family: Goudy Bookletter 1911, sans-serif; font-family: Red/Black, sans-serif; font-family: "Lucida" Grande, sans-serif; font-family: Ahem!, sans-serif; font-family: test@foo, sans-serif; font-family: #POUND, sans-serif; font-family: Hawaii 5-0, sans-serif;
[ <family-name> | <generic-family> ]#where
<family-name> = <string> | <custom-ident>+
<generic-family> = serif | sans-serif | cursive | fantasy | monospace
body { font-family: "Gill Sans Extrabold", Helvetica, sans-serif; } .receipt { font-family: Courier, "Lucida Console", monospace; }
.exampleserif { font-family: Times, "Times New Roman", Georgia, serif; } .examplesansserif { font-family: Verdana, Arial, Helvetica, sans-serif; } .examplemonospace { font-family: "Lucida Console", Courier, monospace; } .examplecursive { font-family: cursive; } .examplefantasy { font-family: fantasy; }
<div class="exampleserif"> This is an example of a serif font. </div> <div class="examplesansserif"> This is an example of a sans-serif font. </div> <div class="examplemonospace"> This is an example of a monospace font. </div> <div class="examplecursive"> This is an example of a cursive font. </div> <div class="examplefantasy"> This is an example of a fantasy font. </div>
Specification | Status | Comment |
---|---|---|
CSS Fonts Module Level 3 The definition of 'font-family' in that specification. | Candidate Recommendation | No significant change |
CSS Level 2 (Revision 1) The definition of 'font-family' in that specification. | Recommendation | No significant change |
CSS Level 1 The definition of 'font-familiy' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 1.0 (1.7 or earlier) | 3.0 | 3.5 | 1.0 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 1.0 (1) | 6.0 | 6.0 | 1.0 |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/font-family