CSS font-family Property
The font-family property specifies the font or prioritized list of fonts used to display text in an HTML element.
Browsers select fonts from the list based on availability and character support. Including fallback fonts helps text remain readable and consistent when a preferred font is unavailable or does not contain a required character.
font-family Syntax
The font-family property accepts one or more font family names separated by commas. The browser considers the fonts in the order listed.
Basic Syntax
selector {
font-family: Arial, sans-serif;
}
Multiple Font Families
selector {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
Generic Font Family
selector {
font-family: serif;
}
System Font Family
selector {
font-family: system-ui, sans-serif;
}
CSS-Wide Keywords
.example {
font-family: inherit;
}
.example {
font-family: initial;
}
.example {
font-family: unset;
}
.example {
font-family: revert;
}
.example {
font-family: revert-layer;
}
CSS-wide keywords must be used alone. They cannot be combined with a comma-separated font family list.
Property Values
The font-family property accepts named font families and generic font family keywords.
| Value | Description |
|---|---|
Arial |
Requests the Arial font family. |
Georgia |
Requests the Georgia font family. |
"Times New Roman" |
Requests a named font family containing spaces. |
serif |
Selects a browser-defined serif font. |
sans-serif |
Selects a browser-defined sans-serif font. |
monospace |
Selects a browser-defined monospaced font. |
cursive |
Selects a cursive or handwriting-style font. |
fantasy |
Selects a decorative font. |
system-ui |
Selects a font associated with the operating system interface. |
ui-serif |
Selects a user-interface serif font where supported. |
ui-sans-serif |
Selects a user-interface sans-serif font where supported. |
ui-monospace |
Selects a user-interface monospaced font where supported. |
ui-rounded |
Selects a rounded user-interface font where supported. |
math |
Selects a font suitable for mathematical notation. |
fangsong |
Selects a Fangsong-style font for Chinese text. |
emoji |
Selects a font intended for emoji characters. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed font family list of the parent element. |
initial |
Restores the initial value, which depends on the user agent. |
unset |
Uses the inherited value because font-family is inherited. |
revert |
Reverts the property according to CSS cascade origins. |
revert-layer |
Reverts the property according to CSS cascade layers. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | Depends on the user agent |
| Inherited | Yes |
| Applies to | All elements and text |
| Computed value | As specified, with font family names normalized as required |
| Animation type | Discrete |
| Percentages | Not applicable |
The browser does not necessarily use one font for every character. If a selected font lacks a character, font fallback may occur for that character or text segment.
How It Works
When the browser displays text, it evaluates the requested font families in order and selects suitable fonts for the text being rendered.
Step 1: Request a Preferred Font
p {
font-family: "Trebuchet MS";
}
The browser attempts to use the named font family.
Step 2: Add Fallback Fonts
p {
font-family: "Trebuchet MS", Arial, sans-serif;
}
If the preferred font is unavailable or cannot display certain characters, the browser can use another font from the list.
Step 3: Include a Generic Family
The final sans-serif keyword allows the browser to choose an appropriate sans-serif font even when neither named family is available.
Step 4: Render the Text
The selected font affects the shape, width, spacing, and appearance of characters. Different fallback fonts may cause text to wrap differently or change the height of a layout.
Important Consideration
The font-family property selects font families, but it does not control font size, weight, or line height. Those characteristics are managed by separate properties or the font shorthand.
Font Fallback
A font fallback list provides alternative fonts when the preferred font cannot be used.
Single Font Without Fallback
p {
font-family: "Example Display Font";
}
If the named font is unavailable, the browser must choose another font using its own fallback behavior.
Font with Fallback List
p {
font-family: "Example Display Font", Arial, Helvetica, sans-serif;
}
The list provides several alternatives and ends with a generic family.
Serif Fallback List
.article-text {
font-family: Georgia, "Times New Roman", serif;
}
Monospace Fallback List
code {
font-family: Consolas, "Courier New", monospace;
}
Fallback for Missing Characters
Even when a preferred font is available, it may not contain every character. For example, a font used for English text may lack certain mathematical symbols, emoji, or characters from another writing system.
The browser can use another suitable font for those characters while continuing to use the preferred font for the remaining text.
Important Consideration
Fallback fonts should have reasonably similar proportions when consistent text wrapping is important. Large differences in character widths can change navigation spacing, button sizes, and paragraph line breaks.
Generic Font Families
Generic font family keywords represent broad categories of fonts rather than specific installed font names.
Common Generic Families
| Family | Typical Appearance |
|---|---|
serif |
Characters with decorative finishing strokes. |
sans-serif |
Characters without traditional serif finishing strokes. |
monospace |
Characters with equal advance widths. |
cursive |
Handwriting or script-like characters. |
fantasy |
Decorative or stylized characters. |
system-ui |
Text matching the general operating system interface style. |
Using a Generic Family
body {
font-family: sans-serif;
}
Using Generic Families as Fallbacks
h1 {
font-family: Georgia, serif;
}
p {
font-family: Arial, sans-serif;
}
code {
font-family: Consolas, monospace;
}
Important Consideration
The actual font selected for a generic family can differ across browsers, operating systems, languages, and user preferences.
Serif Fonts
Serif fonts have small finishing strokes or other decorative details at the ends of many characters. They are commonly used in headings, articles, and traditional typography.
Georgia
.serif-heading {
font-family: Georgia, serif;
}
Times New Roman
.serif-paragraph {
font-family: "Times New Roman", Times, serif;
}
Generic Serif
.serif-text {
font-family: serif;
}
Typical Uses
Serif fonts can be useful for long-form reading, editorial layouts, and designs that call for a traditional appearance.
Important Consideration
Readability depends on the particular typeface, font size, weight, and display conditions. Serif fonts are not automatically more or less readable than sans-serif fonts.
Sans-Serif Fonts
Sans-serif fonts generally have simpler letterforms without traditional serif finishing strokes. They are frequently used for website interfaces, navigation, headings, and body text.
Arial
.sans-heading {
font-family: Arial, sans-serif;
}
Verdana
.sans-paragraph {
font-family: Verdana, Geneva, sans-serif;
}
Helvetica
.sans-interface {
font-family: Helvetica, Arial, sans-serif;
}
Generic Sans-Serif
.sans-text {
font-family: sans-serif;
}
Typical Uses
Sans-serif fonts are commonly used for responsive layouts, forms, buttons, menus, and general website typography.
Important Consideration
Different sans-serif fonts can have substantially different character widths and visual proportions. Test layouts with the actual fallback fonts rather than assuming they will occupy identical space.
Monospace Fonts
Monospace fonts give characters equal advance widths, making them useful for source code, technical examples, and text that requires consistent character alignment.
Consolas
code {
font-family: Consolas, monospace;
}
Courier New
pre {
font-family: "Courier New", Courier, monospace;
}
System Monospace
.code-example {
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
Code Block Example
pre,
code {
font-family: Consolas, "Courier New", monospace;
}
Important Consideration
Monospace fonts help align characters, but they do not replace proper HTML table markup or CSS layout techniques when presenting structured data.
System Font Families
System font family keywords allow websites to use fonts associated with the user's operating system or interface environment.
system-ui
body {
font-family: system-ui, sans-serif;
}
The system-ui keyword selects a suitable user-interface font from the operating system.
User-Interface Serif
.ui-serif {
font-family: ui-serif, serif;
}
User-Interface Sans-Serif
.ui-sans {
font-family: ui-sans-serif, sans-serif;
}
User-Interface Monospace
.ui-code {
font-family: ui-monospace, monospace;
}
User-Interface Rounded
.ui-rounded {
font-family: ui-rounded, sans-serif;
}
Important Consideration
System font families can produce different results on Windows, macOS, Linux, Android, and iOS. Some newer generic families also have more limited browser support than serif, sans-serif, and monospace.
For a consistent branded appearance across platforms, consider a properly licensed web font with suitable fallback families.
Font Family Names
Named font families can be written as quoted strings or, when their names meet CSS identifier rules, as unquoted identifiers.
Single-Word Family Name
p {
font-family: Arial, sans-serif;
}
Quoted Family Name
p {
font-family: "Times New Roman", serif;
}
Unquoted Multiword Name
p {
font-family: Times New Roman, serif;
}
Unquoted multiword font names are permitted when they consist of valid CSS identifiers, but quotation marks often make them easier to read.
Names Containing Special Characters
Font family names containing characters that are not valid in an unquoted identifier sequence should be quoted or appropriately escaped.
Generic Family Keywords
.generic {
font-family: serif;
}
.named {
font-family: "serif";
}
The unquoted serif keyword selects a generic font family. The quoted "serif" value requests a specifically named font family instead.
Important Consideration
Font family names are generally matched without regard to letter case, but spelling and spacing must still identify the intended family.
Custom Fonts
Custom web fonts can be loaded using the CSS @font-face rule and then referenced through font-family.
Define a Custom Font
@font-face {
font-family: "Example Sans";
src: url("/fonts/example-sans.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
Use the Custom Font
body {
font-family: "Example Sans", Arial, sans-serif;
}
Define Multiple Weights
@font-face {
font-family: "Example Sans";
src: url("/fonts/example-sans-regular.woff2") format("woff2");
font-weight: 400;
}
@font-face {
font-family: "Example Sans";
src: url("/fonts/example-sans-bold.woff2") format("woff2");
font-weight: 700;
}
Apply Different Weights
p {
font-family: "Example Sans", Arial, sans-serif;
font-weight: 400;
}
h2 {
font-family: "Example Sans", Arial, sans-serif;
font-weight: 700;
}
Important Consideration
The font URLs shown are examples and require actual font files at those locations. Make sure custom fonts are licensed for web use and include the character sets needed by the website.
The font-display descriptor controls aspects of font loading and fallback behavior. It is declared inside @font-face, not as a regular property on an HTML element.
Font Availability
The browser can only use a requested font if a suitable font face is available through the operating system, browser environment, or a loaded web font.
Installed Font
p {
font-family: Arial, sans-serif;
}
If Arial is available and contains the required characters, the browser can use it.
Unavailable Font
p {
font-family: "Unavailable Example Font", Arial, sans-serif;
}
If the first family is unavailable, the browser can continue to Arial or another suitable fallback.
Missing Character Support
A font may be installed but lack some characters. In that case, the browser can use a fallback font for the unsupported characters.
Different Operating Systems
A font commonly available on one operating system may not be installed on another. Generic font families help accommodate these differences.
Important Consideration
Using font-family does not install a font on the user's device. For a specific custom typeface, load the font through an appropriate web font method.
Inheritance
The font-family property is inherited, allowing descendant elements to use the same font family list unless another rule overrides it.
Set the Body Font
body {
font-family: Arial, sans-serif;
}
Most text elements inherit this font family list unless their styles specify another value.
Override a Heading
body {
font-family: Arial, sans-serif;
}
h1 {
font-family: Georgia, serif;
}
The heading uses Georgia or a serif fallback, while other text continues to use the body font unless overridden.
Explicit Inheritance
button,
input,
select,
textarea {
font-family: inherit;
}
Form controls can have browser-defined font styles. Explicit inheritance is useful when controls should match the surrounding text.
Important Consideration
Inheritance passes the computed font family list to descendants. It does not guarantee that every descendant uses the same physical font face, because font selection also depends on character coverage, weight, style, and other font characteristics.
font-family Example
This example compares common font families. The browser uses the first suitable font in each declaration and falls back when necessary.
HTML Example
<div class="font-family-demo">
<p class="demo-serif">Serif font family example</p>
<p class="demo-sans">Sans-serif font family example</p>
<p class="demo-mono">Monospace font family example</p>
<p class="demo-system">System font family example</p>
<p class="demo-cursive">Cursive font family example</p>
</div>
CSS Example
.font-family-demo p {
margin: 0 0 16px;
font-size: 18px;
}
.demo-serif {
font-family: Georgia, serif;
}
.demo-sans {
font-family: Arial, sans-serif;
}
.demo-mono {
font-family: Consolas, monospace;
}
.demo-system {
font-family: system-ui, sans-serif;
}
.demo-cursive {
font-family: cursive;
}
Serif font family example
Sans-serif font family example
Monospace font family example
System font family example
Cursive font family example
The example demonstrates the visual differences between serif, sans-serif, monospace, system, and cursive font categories.
The exact appearance depends on the fonts available in the browser environment. In particular, generic font families may display differently across operating systems.
Common Mistakes
Several common mistakes can cause unexpected font selection or inconsistent typography.
Forgetting Fallback Fonts
p {
font-family: "Example Custom Font";
}
Without an explicit fallback list, the browser must select a replacement if the preferred font is unavailable.
Using Spaces Instead of Commas
p {
font-family: Arial Helvetica sans-serif;
}
This does not create three separate fallback choices. Font families must be separated by commas.
Quoting Generic Font Keywords
p {
font-family: "sans-serif";
}
Quotation marks make this a named font family rather than the generic sans-serif keyword.
Assuming a Font Is Installed Everywhere
Font availability differs across operating systems and devices. Use fallback fonts or load an appropriate web font.
Confusing Font Family with Font Weight
The font-family property chooses the family, while font-weight selects a weight within that family.
Confusing Font Family with Font Size
Font size must be set using font-size or the font shorthand. It cannot be included in a font-family declaration.
Ignoring Missing Characters
A font can be available but lack certain characters. Provide suitable fallback fonts when multilingual text, mathematical symbols, or emoji are expected.
Expecting Identical Rendering Everywhere
Font rendering can vary because of operating system font files, browser rendering engines, antialiasing, and user preferences.
Important Considerations
Keep the following points in mind when using the font-family property:
- Purpose: Specifies the font family or prioritized list of font families used for text.
- Initial value: Depends on the browser and user agent.
- Inheritance: The property is inherited.
- Applies to: All elements and text.
- Fallback order: Fonts are considered in the order listed.
- Separators: Separate font family choices with commas.
- Generic fallback: Include an appropriate generic family at the end of the list.
- Named fonts: Request specific font families such as Arial or Georgia.
- Quoted names: Use quotation marks for names containing special characters or when needed for clarity.
- Generic keywords: Do not quote generic font family keywords.
- Serif: Represents fonts with traditional serif details.
- Sans-serif: Represents fonts without traditional serif finishing strokes.
- Monospace: Represents fonts with equal character advance widths.
- System fonts: Allow typography to follow the user's operating system interface.
- Custom fonts: Can be defined using
@font-face. - Font loading: Specifying a font family does not automatically download or install it.
- Character coverage: Different fonts may be selected for characters missing from the preferred family.
- Layout changes: Different fonts can change text width, wrapping, and element dimensions.
- Font weight: Controlled separately using
font-weight. - Font size: Controlled separately using
font-size. - Font shorthand: The
fontproperty can set font family along with several other font settings. - Accessibility: Choose readable fonts and respect user font preferences.
- Browser compatibility: The core property is supported across modern browsers.
For reliable website typography, define a preferred font, provide suitable fallback families, and test the layout with different fonts and devices. This helps maintain readability when the preferred font cannot be used.
Browser Support
The CSS font-family property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
Named font families and traditional generic families such as serif, sans-serif, and monospace have long-standing support. Some newer generic families may have more limited compatibility.
Supported Example
body {
font-family: Arial, Helvetica, sans-serif;
}
System Font Example
body {
font-family: system-ui, sans-serif;
}
Feature Detection
@supports (font-family: system-ui) {
body {
font-family: system-ui, sans-serif;
}
}
The @supports rule checks whether the browser accepts the declaration. It does not guarantee that a particular font is available or that a generic family maps to a specific typeface.
Compatibility Considerations
Test font fallback lists across operating systems, especially when using newer generic font families or custom web fonts. The exact rendered font may differ even when the property itself is fully supported.
For current compatibility information, visit Can I Use? and search for the relevant font family feature.
Specifications
The font-family property is defined in the CSS Fonts Module, which describes font family selection, fallback behavior, and font matching.
CSS Fonts Module Level 4: font-family Property
Earlier specifications define the established behavior of named font families and traditional generic families.
CSS Fonts Module Level 3: font-family Property
For additional explanations and examples, see MDN Web Docs.
