CSS:font
From MDC
[edit] Summary
The font property is a shorthand property for setting font-style, font-variant, font-weight, font-size, line-height and font-family at the same place in the style sheet.
- Initial value: refer to individual properties
- Applies to: all elements
- Inherited: yes
- Percentages: N/A
- Media:
visual - Computed value:
[edit] Syntax
font: [ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family>
font: caption | icon | menu | message-box | small-caption | status-bar | -moz-window | -moz-document | -moz-workspace | -moz-desktop | -moz-info | -moz-dialog | -moz-button | -moz-pull-down-menu | -moz-list | -moz-field
font: inherit
[edit] Values
Using the font shorthand property sets the longhand properties as specified, and sets all other font-related properties to their initial values.
See font-style, font-variant, font-weight, font-size, and font-family for legal values of each property.
System fonts can also be specified using the font property, instead of specifying individual longhand properties:
- caption
- The font used for captioned controls (e.g., buttons, drop-downs, etc.).
- icon
- The font used to label icons.
- menu
- The font used in menus (e.g., dropdown menus and menu lists).
- message-box
- The font used in dialog boxes.
- small-caption
- The font used for labeling small controls.
- status-bar
- The font used in window status bars.
- -moz-window
- -moz-document
- -moz-workspace
- -moz-desktop
- -moz-info
- -moz-dialog
- -moz-button
- -moz-pull-down-menu
- -moz-list
- -moz-field
[edit] Examples
/* Set the font size to 12pt and the line height to 14pt. Set the font family to sans-serif */
p { font: 12pt/14pt sans-serif }
/* Set the font size to 80% of the parent element or default value (if no parent element present)
and set the font family to sans-serif */
p { font: 80% sans-serif }
/* Set the font weight to bold, the font-style to italic, the font size to large,
and the font family to serif. */
p { font: bold italic large serif }
[edit] Notes
The font-size and font-family parts of the shorthand are mandatory. Omitting them is a syntax error, and causes the entire declaration to be ignored.
Properties for which no values are given are set to their initial value, which is normal for all properties that can be omitted (font-style, font-variant, font-weight, and line-height).
The font-size-adjust property is also set to its initial value (none) when the font shorthand property is specified.
[edit] Specifications
- CSS 1
- CSS 2 (for
font-size-adjust) - CSS 2.1
- css3-ui (for new system font values)
[edit] Browser compatibility
| Browser | Lowest Version |
|---|---|
| Internet Explorer | 3 |
| Netscape | 4 |
| Opera | 3.5 |
[edit] See also
font,
font-family,
font-size,
font-size-adjust,
font-stretch,
font-style,
font-variant,
font-weight,
@font-face