font-family
CSS property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Values are separated by commas to indicate that they are alternatives. The browser will select the first font in the list that is installed or that can be downloaded using a
@font-face
at-rule.
It is often convenient to use the shorthand property
font
to set
font-size
and other font related properties all at once.
You should always include at least one generic family name in a
font-family
list, since there's no guarantee that any given font is available. This lets the browser select an acceptable fallback font when necessary.
font-family
property specifies a list of fonts, from highest priority to lowest. Font selection
does not
simply stop at the first font 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 for a needed character, the latter fonts are tried. (However, this doesn't work in Internet Explorer 6 or earlier.) When a font is only available in some
styles
,
variants
,或
sizes
, those properties may also influence which font family is chosen.
/* 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; font-family: system-ui; font-family: ui-serif; font-family: ui-sans-serif; font-family: ui-monospace; font-family: ui-rounded; font-family: emoji; font-family: math; font-family: fangsong; /* Global values */ font-family: inherit; font-family: initial; font-family: unset;
font-family
property lists one or more font families, separated by commas. Each font family is specified as either a
<family-name>
或
<generic-name>
值。
The example below lists two font families, the first with a
<family-name>
and the second with a
<generic-name>
:
font-family: Gill Sans Extrabold, sans-serif;
<family-name>
The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted.
<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
system-ui
ui-serif
ui-sans-serif
ui-monospace
ui-rounded
math
emoji
fangsong
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;
| 初始值 | depends on user agent |
|---|---|
| 适用于 |
所有元素。它还适用于
::first-letter
and
::first-line
.
|
| 继承 | yes |
| 计算值 | 如指定 |
| 动画类型 | discrete |
[ <family-name> | <generic-family> ]#where
<family-name> = <string> | <custom-ident>+
<generic-family> = serif | sans-serif | cursive | fantasy | monospace
.serif {
font-family: Times, Times New Roman, Georgia, serif;
}
.sansserif {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.monospace {
font-family: Lucida Console, Courier, monospace;
}
.cursive {
font-family: cursive;
}
.fantasy {
font-family: fantasy;
}
.emoji {
font-family: emoji;
}
.math {
font-family: math;
}
.fangsong {
font-family: fangsong;
}
<div class="serif"> This is an example of a serif font. </div> <div class="sansserif"> This is an example of a sans-serif font. </div> <div class="monospace"> This is an example of a monospace font. </div> <div class="cursive"> This is an example of a cursive font. </div> <div class="fantasy"> This is an example of a fantasy font. </div> <div class="math"> This is an example of a math font. </div> <div class="emoji"> This is an example of an emoji font. </div> <div class="fangsong"> This is an example of a fangsong font. </div>
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Fonts Module Level 4
The definition of 'generic font families' in that specification. |
工作草案 |
Adds new generic font families, specifically:
system-ui
,
ui-serif
,
ui-sans-serif
,
ui-monospace
,
ui-rounded
,
emoji
,
math
,和
fangsong
.
|
|
CSS Fonts Module Level 3
The definition of 'font-family' in that specification. |
候选推荐 | No significant change |
|
CSS Level 2 (Revision 1)
The definition of 'font-family' in that specification. |
推荐 | No significant change |
|
CSS Level 1
The definition of 'font-family' in that specification. |
推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
font-family
|
Chrome 完整支持 1 | Edge 完整支持 12 |
Firefox
完整支持
1
注意事项
|
IE 完整支持 3 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 1 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
system-ui
|
Chrome 完整支持 56 | Edge 完整支持 79 |
Firefox
不支持
No
|
IE 不支持 No | Opera 完整支持 43 |
Safari
完整支持
9
注意事项
Alternate Name
|
WebView Android 完整支持 56 | Chrome Android 完整支持 56 | Firefox Android 不支持 No | Opera Android 完整支持 43 |
Safari iOS
完整支持
9
Alternate Name
|
Samsung Internet Android 完整支持 6.0 |
完整支持
不支持
见实现注意事项。
使用非标名称。
font
font-family
font-feature-settings
font-kerning
font-language-override
font-optical-sizing
font-size
font-size-adjust
font-smooth
font-stretch
font-style
font-synthesis
font-variant
font-variant-alternates
font-variant-caps
font-variant-east-asian
font-variant-ligatures
font-variant-numeric
font-variant-position
font-variation-settings
font-weight
line-height
line-height-step