CSS font-family Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography

What You’ll Learn

The font-family property sets the typeface for text using a prioritized font stack. It is one of the most important properties for readable, on-brand web typography.

01

Font stack

Comma list.

02

Fallbacks

First match wins.

03

Generic

serif, sans-serif.

04

Quotes

Multi-word names.

05

Web fonts

@font-face.

06

Inherited

From parent.

Introduction

The font-family property in CSS is used to specify the typeface of text. It allows web developers to define a prioritized list of font family names and/or generic family names for the selected element.

Definition and Usage

This property plays a crucial role in controlling the typography of a web page, ensuring that text is rendered in a visually appealing and readable manner. List fonts from most preferred to most fallback, and end with a generic family like sans-serif or serif whenever possible.

💡
Beginner Tip

Think of font-family as a backup plan. The browser tries each font left to right until it finds one installed on the device or loaded via a web font.

📝 Syntax

The syntax for the font-family property involves listing one or more font family names, separated by commas. Generic family names should always be included as a fallback:

syntax.css
element {
  font-family: "font-name", generic-family;
}

Here, "font-name" can be a specific font family, and generic-family is one of the five generic font families: serif, sans-serif, monospace, cursive, or fantasy.

Basic Example

font-family-basic.css
p {
  font-family: "Arial", sans-serif;
}
font-family: Georgia, serif; font-family: system-ui, sans-serif; font-family: "Courier New", monospace;

Default Value

The default value of the font-family property depends on the user agent (browser). Typically, it is set to the browser's default sans-serif font.

Syntax Rules

  • Separate multiple font names with commas, most preferred first.
  • Quote names that contain spaces: "Times New Roman".
  • Always include a generic family as the final fallback when possible.
  • The property is inherited — set it on body for site-wide typography.
  • Font names are case-sensitive on some systems; match official spelling.

⚡ Quick Reference

QuestionAnswer
Initial valueBrowser-dependent (usually a sans-serif UI font)
Applies toAll elements
InheritedYes
Value typeComma-separated list of font family names
Common patternfont-family: "Segoe UI", system-ui, sans-serif;

💎 Property Values

Specific font family names

Named typefaces installed on the user's device or loaded as web fonts, such as Arial, Times New Roman, and Courier New.

Generic family names

Generic familyDescription
serifFonts with small strokes at letter ends, such as Times-style typefaces.
sans-serifFonts without those strokes, such as Arial-style typefaces.
monospaceFonts where every character has the same width, ideal for code.
cursiveFonts that emulate handwriting.
fantasyDecorative display fonts that do not fit other categories.

System UI keywords

Modern stacks often include system-ui or ui-sans-serif so text matches the operating system interface font before falling back to generic families.

Common Font Stacks

StackBest for
system-ui, sans-serifClean UI text that matches the OS
Georgia, "Times New Roman", serifArticles, long-form reading
"Segoe UI", Roboto, Arial, sans-serifCross-platform body copy
ui-monospace, "Cascadia Code", monospaceCode blocks and terminals

👀 Live Preview

The same sentence in sans-serif, serif, and monospace stacks:

Arial, sans-serif The quick brown fox jumps over the lazy dog.
Georgia, serif The quick brown fox jumps over the lazy dog.
"Courier New", monospace The quick brown fox jumps over the lazy dog.

Examples Gallery

In this example, we set the font family of a paragraph to Arial with a sans-serif fallback — plus serif stacks, monospace code, and a web font with @font-face.

🔠 Font Stacks

Start with the reference example — a named font with a generic fallback.

Example 1 — Arial with sans-serif Fallback

Set paragraph text to Arial. If Arial is unavailable, the browser uses any sans-serif font.

font-family-arial.html
<style>
  p {
    font-family: "Arial", sans-serif;
  }
</style>

<p>
  This paragraph uses Arial. If Arial is not available, it falls back to a sans-serif font.
</p>
Try It Yourself

How It Works

The browser checks for Arial first. If it is not installed, it picks another sans-serif font from the system.

Example 2 — Serif Reading Stack

Use multiple serif options for article content with graceful degradation.

font-family-serif.css
article {
  font-family: Georgia, "Times New Roman", Times, serif;
}
Try It Yourself

How It Works

Each name is tried in order. Quoted multi-word names like "Times New Roman" are parsed correctly because of the quotes.

💻 Code & Web Fonts

Choose monospace for code and load custom fonts when built-in options are not enough.

Example 3 — Monospace for Code

Apply a monospace stack to <code> elements so characters align in columns.

font-family-monospace.css
code {
  font-family: ui-monospace, "Cascadia Code", "Courier New", monospace;
}
Try It Yourself

How It Works

Monospace fonts give each character equal width, which makes code snippets and terminal output easier to scan.

Example 4 — Custom Web Font

Load a font file with @font-face, then reference its family name in font-family.

font-family-webfont.css
@font-face {
  font-family: "Brand Sans";
  src: url("/fonts/brand-sans.woff2") format("woff2");
}

h1 {
  font-family: "Brand Sans", system-ui, sans-serif;
}
Try It Yourself

How It Works

@font-face registers a downloadable font. Your stack still needs fallbacks in case the file is blocked or slow to load.

♿ Accessibility

  • Choose readable typefaces for body text; avoid decorative fonts for long paragraphs.
  • Provide fallbacks so text remains legible if a custom font fails to load.
  • Do not use font choice alone to convey meaning or status.
  • Test loaded web fonts for clarity at small sizes and high zoom levels.
  • Respect user font settings by using relative sizes and sensible system fallbacks.

🧠 How font-family Works

1

You define a font stack

List preferred fonts in order, ending with a generic family when possible.

Declaration
2

Browser checks availability

Each name is tested left to right — installed fonts and loaded web fonts qualify.

Matching
3

First match is used

If no named font matches, the generic family selects an appropriate system typeface.

Fallback
=

Rendered typography

Text displays in the best available font for the user's device and your design.

🖥 Browser Compatibility

The font-family property is universally supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is one of the most fundamental CSS properties for web typography.

Baseline · Universal support

font-family everywhere

Named fonts, generic families, and font stacks work in every browser, including legacy environments.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
font-family property 99% supported

Bottom line: font-family is essential and safe everywhere. Pair with web font loading strategies for custom brand typefaces.

🎉 Conclusion

The font-family property is a key tool for web developers to control the typography of their web pages. By specifying a list of preferred fonts along with generic fallbacks, you can ensure that your text is rendered in a way that matches your design vision.

Experiment with different font families to see how they impact the look and feel of your web projects. Build thoughtful stacks, quote multi-word names, and always keep a readable fallback at the end of the list.

💡 Best Practices

✅ Do

  • End stacks with a generic family like sans-serif or serif
  • Quote font names that contain spaces
  • Set base typography on body so children inherit it
  • Include system fonts like system-ui for native feel
  • Provide fallbacks when using custom web fonts

❌ Don’t

  • Rely on a single font name with no fallback
  • Use too many fonts on one page — it hurts consistency
  • Forget quotes on names like Times New Roman
  • Choose decorative fonts for long body paragraphs
  • Assume every user has the same fonts installed

Key Takeaways

Knowledge Unlocked

Five things to remember about font-family

Use these points when choosing typefaces for your site.

5
Core concepts
02

First match

Browser picks one.

Behavior
serif 03

Generic families

Final fallback.

Values
" 04

Quote names

Spaces need quotes.

Syntax
🔁 05

Inherited

Set on body.

Cascade

❓ Frequently Asked Questions

The font-family property sets the typeface for text. You provide a prioritized list of font names; the browser uses the first available font in the list.
Generic families like sans-serif or serif act as a final fallback if none of your named fonts are installed. They help ensure text still renders in an appropriate style.
Quote font names that contain spaces, digits at the start, or special characters, such as Times New Roman. Single-word names like Arial usually work with or without quotes.
A font stack is the comma-separated list in font-family, ordered from most preferred to fallback options, ending with a generic family when possible.
font-family only chooses the typeface. The font shorthand can also set size, weight, style, and line-height in the same declaration.

Practice in the Live Editor

Open the HTML editor, change font-family stacks, and compare how sans-serif, serif, and monospace render.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful