CSS: font-family

By Xah Lee. Date: . Last updated: .

font-family property lets you specify a font.

Font name is not case sensitive.

Example:

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

Example:

h1
{
font-family: Georgia, serif;
}

Example:

pre
{
font-family: Courier, monospace;
}

Possible Values

Value can be a single value e.g.

font-family: Courier;

, or a sequence of values, like this

font-family: Courier, Menlo, monospace;

Example:

pre
{
font-family: "andale mono", courier, menlo, monospace;
}

Browser will use the first one available on user's system.

Generic Font Names

There are these special generic values:

Note, the choice of these can be set in browser preference by user.

Examples:

This is Your Default serif Font

This is Your Default sans-serif Font

This is Your Default monospace Font

This is Your Default cursive Font

This is Your Default fantasy Font

This is Your system-ui Font

Here's how it looks in macOS.

css font family macOS 2018-11 a80a8
css font family macOS 2018-11

Serif vs Sans-Serif Font

Serif font example. ABC

Sans serif font example. ABC

Font Name

For font name, if the name contains space, it needs to be quoted. e.g.

h1
{
font-family:"Times New Roman", serif;
}

Font Name is Not Case Sensitive

For font examples, see Standard Web Fonts

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

CSS Basics

  1. Basics
  2. Tag Matching Tutorial
  3. Selector Syntax
  4. Units

Color

  1. Color Syntax
  2. Color Names
  3. Opacity
  4. Linear Gradient
  5. Radial Gradient

Font

  1. font-family
  2. Standard Web Fonts
  3. font-size
  4. Meaning of Font Size
  5. Font Weight
  6. Chinese Font Names

Box Model

  1. Border
  2. Outline
  3. Margin vs Padding
  4. Box Sizing

Layout

  1. Layout Tutorial
  2. Display Property
  3. Position: static, relative, fixed, absolute
  4. Pure CSS Table
  5. Tabbed Menu
  6. 3 Columns Page Layout
  7. Multi-Column Layout for Text Flow
  8. Fix Element to Window
  9. Centering
  10. Flowing List
  11. z-index
  12. Text Over Image
  13. Text Flow Around Image
  14. OverFlow, Scrollbar

Transform/Animation

  1. 2D Transform
  2. Transition
  3. Animation

Line Wrap, Justification

  1. Line Wrap
  2. Text Alignment, Justification
  3. Match first-letter and first-line
  4. “:before”, “:after”
  5. Text Decoration: Underline, Overline, Line-Through
  6. Letter Spacing, Word Spacing

Box Decoration

  1. Box Shadow
  2. Text Shadow
  3. Round Corners
  4. Background Image
  5. Image Rollover

Misc

  1. Computed Style
  2. Pseudo Class vs Pseudo Element
  3. Media Query
  4. Variable
  5. calc
  6. Reset
  7. user-select
  8. Data URI Scheme
  9. protocol-relative URL
  10. Default Unit
  11. Declaring Character Set in CSS File
  12. Jargons Explained: Tag, Element, Node, Object, Attribute, Property, Method
  13. Display Table on Small Screen
  14. Fixed Aspect Ratio
  15. Add Icon to Links
  16. Progress Bar Example

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. CSS
  3. JavaScript
  4. JS Obj Ref
  5. DOM
  6. SVG
  7. Blog