Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Font Family

CSS Font Family

CSS CODES & EXAMPLES

CSS Font Family

Learn how to choose, combine and control fonts in CSS using font-family, generic font families, fallback fonts and font stacks.

01

What is font-family?

Choose the typeface used by an element

The CSS font-family property specifies the typeface that should be used to display text. You can provide one font, several fallback fonts, or a generic font family.

Syntax: font-family: font-name, fallback, generic-family;
02

Basic Example

Using a single font family
basic-font-family.css
body {
  font-family: Arial;
}
This text uses Arial.
03

Serif Fonts

Traditional letter styling

Serif fonts have small decorative strokes at the ends of letters. They are commonly used in books, articles and editorial designs.

serif.css
h1 {
  font-family: Georgia, serif;
}
Georgia is a serif font.
04

Sans-Serif Fonts

Clean and modern typography

Sans-serif fonts do not have decorative strokes at the ends of letters. They are widely used in websites and modern interfaces.

sans-serif.css
body {
  font-family: Arial, sans-serif;
}
Arial is a common sans-serif font.
05

Monospace Fonts

Equal-width characters

In a monospace font, each character generally occupies the same horizontal amount of space. These fonts are commonly used for source code and programming examples.

monospace.css
code {
  font-family: "Courier New", monospace;
}
console.log(“Hello World”);
07

Font Stack

Provide fallback fonts

A font stack contains multiple font choices. The browser attempts to use the first available font and moves to the next option when necessary.

font-stack.css
body {
  font-family:
    Arial,
    Helvetica,
    sans-serif;
}
Best practice: Always include a suitable generic fallback family at the end of your font stack.
08

Quoted Font Names

Fonts containing spaces

Font names containing spaces are normally written inside quotation marks.

quoted-font.css
body {
  font-family: "Times New Roman", serif;
}

.title {
  font-family: "Courier New", monospace;
}
09

Different Elements, Different Fonts

Apply font families independently
multiple-fonts.css
h1 {
  font-family: Georgia, serif;
}

p {
  font-family: Arial, sans-serif;
}

code {
  font-family: "Courier New", monospace;
}

Computer Education

Learn practical computer skills with structured lessons, examples and hands-on practice.

font-family: Arial, sans-serif;
10

System Font Stack

Modern interface typography
system-ui.css
body {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
Modern System Font Example
11

Google Font Example

Using a web font

Web fonts allow websites to use fonts that may not already be installed on the visitor’s device.

web-font.html
<link
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap"
  rel="stylesheet">

body {
  font-family: "Poppins", sans-serif;
}
Poppins Web Font Example
13

Inheritance

Child elements can inherit the parent’s font
inheritance.css
body {
  font-family: Arial, sans-serif;
}

.card {
  font-family: inherit;
}

Inherited Font

This content uses the font inherited from its parent.

14

Best Practices

Use font-family correctly
✓ Use Fallbacks

Provide backup fonts when using a specific typeface.

✓ Use Generic Families

Finish a font stack with serif, sans-serif or another appropriate generic family.

✓ Keep Typography Consistent

Use a small number of font families for a clean design.

✓ Consider Readability

Choose fonts that remain easy to read across devices.

15

Quick Revision

Important points
font-family Specifies the font family.
serif Generic serif category.
sans-serif Generic sans-serif category.
monospace Equal-width character category.
font stack Multiple font choices with fallbacks.
system-ui Uses the system interface font.
16

Practice Task

Build your own font stack

🎯 Your Challenge

Create a professional webpage typography system.

  • Use a serif font for the main heading.
  • Use a sans-serif font for paragraphs.
  • Use a monospace font for code.
  • Add at least one fallback font.
  • Use a generic family at the end of each stack.
17

CSS Font Family Live Runner

Experiment with font-family
LIVE PREVIEW
`;document.getElementById( "sncecFFPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFFRun();} );

CSS Flex Flow

  • 19/08/2026

HTML Div & Span

  • 17/08/2026

CSS Flex Wrap

  • 19/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *