XML technologies / CSS / Advanced websites with CSS / CSS property reference / font

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The shorthand property font lets you declare the font properties font-style, font-variant, font-weight, font-size, line-height and font-family together in a single declaration.

Unless one of the CSS constants listed below is declared, at least font-size and font-family must be declared. Other properties are optional and reset to their defaults unless specified in the declaration of font.

Inherited: yes

See also: font-style, font-variant, font-weight, font-size, line-height, font-family

Values

The syntax for the property font is as follows:

font: [style] [variant] [weight] size [/ line-height] family

Bracketed values are optional. The first three values— style, variant and weight —may appear in any order and accept the valid values of font-style, font-variant and font-weight respectively. The declaration of line-height comes immediately after size and a slash (/). For size, declare a CSS measurement, a percentage or a constant valid for font-size; for family, declare any valid value of font-family.

Since CSS2, an alternative syntax using shorthand constants is also valid:

font: konstante

konstante represents one of the following constants, each defining a detailed font configuration with fixed values for typeface, size, style, and so on:

  • caption

  • icon

  • menu

  • message-box

  • small-caption

  • status-bar

Fonts displayed with these constants may differ between browsers, operating systems and individual user settings.

Default value: none

Compatibility

CSS version: 1 (shorthand constants only in CSS2)

Works to some extent in all CSS-capable browsers, according to their support for individual font properties.

Examples

The following style rule uses every font property in font to define paragraph fonts:

p {
 normal normal normal 11pt/12pt Myriad, Helvetica, sans-serif;
}

The following style rule assigns elements caption a font definition using a constant:

caption {
 font: caption;
}

  

 

 

 

back to top