The CSS reference

"font-family" - css property (v. css 1)

  • To specify the font family for a text.
  • Unlike most other CSS properties, values are separated by a comma to indicate that they are alternatives.
  • Initial value: depends on user agent
  • The property is inherited
  • HTML usage: all elements
  • Browsers that support the font-family - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari
Typical usage:
body { font-family: Gill, Helvetica, sans-serif }

Possible font-family values:

value Comments CSS
family-name The name of a font family of choice. In the example above, "Gill" and "Helvetica" are font families. 1
generic-family In the example above, the last value is a generic family name. The following generic families are defined:
  • 'serif' (e.g., Times)
  • 'sans-serif' (e.g., Helvetica)
  • 'cursive' (e.g., Zapf-Chancery)
  • 'fantasy' (e.g., Western)
  • 'monospace' (e.g., Courier)
inherit Will inherit the value from parent specification. This property value is new with CSS 2. 2

Javascript access:

// To SET values ([o] is the target object)
[o].style.fontFamily="font-family values"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:
var value=cStyle.fontFamily;
// Returns a comma seperated list of font families
// Opera will return only the first in the list of font families.
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.