Web/CSS/font-family

From Get docs


The 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.

The 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, or sizes, those properties may also influence which font family is chosen.

Syntax

/* 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;

The font-family property lists one or more font families, separated by commas. Each font family is specified as either a <family-name> or a <generic-name> value.

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;

Values

<span id="<family-name>"><family-name>
The name of a font family. For example, "Times" and "Helvetica" are font families. Font family names containing whitespace should be quoted.
<span id="<generic-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
Glyphs have finishing strokes, flared or tapering ends, or have actual serifed endings. E.g. Lucida Bright, Lucida Fax, Palatino, "Palatino Linotype", Palladio, "URW Palladio", serif.
sans-serif
Glyphs have stroke endings that are plain. E.g. "Open Sans", "Fira Sans", "Lucida Sans", "Lucida Sans Unicode", "Trebuchet MS", "Liberation Sans", "Nimbus Sans L", sans-serif.
monospace
All glyphs have the same fixed width. E.g. "Fira Mono", "DejaVu Sans Mono", Menlo, Consolas, "Liberation Mono", Monaco, "Lucida Console", monospace.
cursive
Glyphs in cursive fonts generally have either joining strokes or other cursive characteristics beyond those of italic typefaces. The glyphs are partially or completely connected, and the result looks more like handwritten pen or brush writing than printed letterwork. E.g. "Brush Script MT", "Brush Script Std", "Lucida Calligraphy", "Lucida Handwriting", "Apple Chancery", cursive.
fantasy
Fantasy fonts are primarily decorative fonts that contain playful representations of characters. E.g. Papyrus, Herculanum, Party LET, Curlz MT, Harrington, fantasy.
system-ui
Glyphs are taken from the default user interface font on a given platform. Because typographic traditions vary widely across the world, this generic is provided for typefaces that don't map cleanly into the other generics. This is example system-ui text.
ui-serif
The default user interface serif font. This is example ui-serif text.
ui-sans-serif
The default user interface sans-serif font. This is example ui-sans-serif text.
ui-monospace
The default user interface monospace font. This is example ui-monospace text.
ui-rounded
The default user interface font that has rounded features. This is example ui-rounded text.
math
This is for the particular stylistic concerns of representing mathematics: superscript and subscript, brackets that cross several lines, nesting expressions, and double struck glyphs with distinct meanings. This is some example math text: ax² + bx + c = 0.
emoji
Fonts that are specifically designed to render emoji. This is some example emoji text: ✝♾.
fangsong
A particular style of Chinese characters that are between serif-style Song and cursive-style Kai forms. This style is often used for government documents. This is some example fangsong text with the Chinese characters for "fangsong" in traditional and simple forms, respectively: 仿宋體 仿宋体.

Valid family names

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;

Formal definition

Initial value depends on user agent
Applies to all elements. It also applies to ::first-letter and ::first-line.
Inherited yes
Computed value as specified
Animation type discrete

Formal syntax

[ <family-name> | <generic-family> ]#where <family-name> = <string> | <custom-ident>+<generic-family> = serif | sans-serif | cursive | fantasy | monospace

Examples

Some common font families

.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;
}

Specifications

Specification Status Comment
CSS Fonts Module Level 4The definition of 'generic font families' in that specification. Working Draft Adds new generic font families, specifically: system-ui, ui-serif, ui-sans-serif, ui-monospace, ui-rounded, emoji, math, and fangsong.
CSS Fonts Module Level 3The 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 1The definition of 'font-family' in that specification. Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
font-family Chrome

Full support 1

Edge

Full support 12

Firefox Full support 1

Notes'

Full support 1

Notes'

Notes' Not supported on option elements. See bug 1536148.

IE

Full support 3

Opera

Full support 3.5

Safari

Full support 1

WebView Android

Full support 1

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support 10.1

Safari iOS

Full support 1

Samsung Internet Android

Full support 1.0

system-ui Chrome

Full support 56

Edge

Full support 79

Firefox No support No


No support No


Full support 43

Notes' Alternate Name'

Notes' Supported on macOS only. Alternate Name' Uses the non-standard name: -apple-system

IE

No support No

Opera

Full support 43

Safari Full support 9

Notes' Alternate Name'

Full support 9

Notes' Alternate Name'

Notes' Supported since macOS 10.11. Alternate Name' Uses the non-standard name: -apple-system

WebView Android

Full support 56

Chrome Android

Full support 56

Firefox Android

No support No

Opera Android

Full support 43

Safari iOS Full support 9

Alternate Name'

Full support 9

Alternate Name'

Alternate Name' Uses the non-standard name: -apple-system

Samsung Internet Android

Full support 6.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.'
See implementation notes.
Uses a non-standard name.'
Uses a non-standard name.