Little Web Hut

CSS 2.1 Reference: font-family Property

CSS font-family Property
Syntax
selector {font-family: family, family;}
  • family occurs one or more times. If it occurs more than once then the values must be separated by commas. It is specified by using a family-name or one of the following keywords: serif, sans-serif, cursive, fantasy, or monospace. Above is a sample of family occurring two times.
(OR)
selector {font-family: value;}
  • value is specified by using the keyword inherit.
Usage

The font-family property is used to specify a comma separated list of font families. The font family list is prioritized with the highest priority occurring first. If the first font family is not available then the second one, if available, will be used. If the second one is not available then the third one, if available, will be used, and so on.

The keywords represent generic font families. It is common to list 2 or 3 family names followed by a keyword. By placing the keyword last, it will only be used if the other family names are not available. See the following example where the keyword serif is listed last.

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

The "Times New Roman" family name, shown above, is enclosed within quotation marks. If quotation marks are not used then some characters (e.g., punctuation and digits) may need escaping. Therefore it is suggested that family names containing white spaces, punctuation marks, or digits, be enclosed within quotation marks to avoid escaping mistakes. Keyword names, however, must NOT be enclosed in quotation marks.


CSS Example: The font-family properties are set using 2 different family types.
  #tst1 {font-family: Georgia, "Times New Roman", Times, serif;}
  #tst2 {font-family: Helvetica, Arial, sans-serif;}
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style

Keywords
  • serif - Generic family name.
  • sans-serif - Generic family name.
  • cursive - Generic family name.
  • fantasy - Generic family name.
  • monospace - Generic family name.
  • inherit - A single inherit keyword is used to specify that the values for this property should be taken from the parent element. If inherit is used with the root element, then the initial values for this property will be used. When the inherit keyword is used, no other property values are allowed.
Applies To All elements
Inherited Yes
Initial Value Browser dependent


font-family Property Examples
Test It HTML StyleTest It HTML StyleTest It HTML5 StyleThe font-family properties are set using 2 different family types.