font property

Specifies a combination of separate font properties of the object. Alternatively, sets or retrieves one or more of six user-preference fonts.

Syntax

font: [ [ font-style || font-variant || font-weight ]? font-size [ / line-height ]? font-family ] | caption | icon | menu | message-box | small-caption | status-bar

Property values

A variable of type String that specifies or receives up to six of the following space-delimited property values. Alternatively, sets or retrieves the six listed text fonts.

font-style

Any of the range of font-style values available to the font-style property.

font-variant

Any of the range of font-variant values available to the font-variant property.

font-weight

Any of the range of font-weight values available to the font-weight property.

font-size

Any of the range of font-size values available to the font-size property. When this value is an integer followed by a percent (%), the value is a percentage of the parent object's font size.

line-height

Any of the range of line-height values available to the line-height property. When used with the font property, this attribute must include a slash (/) before the value. Line height percentage values are calculated as a percentage of the font size of the element itself, not of the parent.

font-family

Any of the range of font-family values available to the font-family property. This property can be set to multiple comma-separated values. Its default value depends on user settings.

caption

User-preference font used in objects that have captions—buttons, labels, and so on.

icon

User-preference font used in icon labels.

menu

User-preference font used in menus.

message-box

User-preference font used in dialog boxes.

small-caption

User-preference font used in small controls.

status-bar

User-preference font used in window status bars.

CSS information

Applies ToAll elements
Mediavisual
Inherited1
Initial Valuethe concatenation of the initial values of its longhand properties

Remarks

This is a composite property that specifies up to six font values. The font-style, font-variant, and font-weight values may appear in any order before font-size. However, the font-size, line-height, and font-family properties must appear in the order listed. Setting the font property also sets the component properties. In this case, the string must be a combination of valid values for the component properties; only font-family may have more than one value. If the string does not contain a value for a component property, that property is set to its default, regardless of prior settings for that component property.

As of Microsoft Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, the following conditions apply to this property.

  1. The font-size and font-family values must be declared. If font-size and font-family are not declared, or are not in the correct order, the font property is ignored.
  2. All specified values must appear in the correct order. Otherwise, the font property is ignored.
  3. In standards-compliant mode, the default font-size is small, not medium. If not explicitly set, font-size returns a point value.

For more information about standards-compliant parsing and the !DOCTYPE declaration, see CSS Enhancements in Internet Explorer 6.

Examples

This example displays three lines of text using different font settings.


body {
  font: Garamond, serif;
}
.sans-serif {
  font: italic small-caps 12pt Arial, sans-serif;
}
.monospace {
  font: bold 14pt Courier, monospace;
}


<body>
  <p>Lorem ipsum dolor sit amet... (font: Garamond, serif)</p>
  <p class="sans-serif">Lorem ipsum dolor sit amet... (font: italic small-caps 12pt Arial, sans-serif)</p>
  <p class="monospace">Lorem ipsum dolor sit amet... (font: bold 14pt Courier, monospace)</p>
</body>

The following image shows the result. The first line of text shows the default body element font setting that specifies a font from a serif font family. The second line of text shows a font setting that specifies an italic font style, small-caps font variant, 12-point font size, and a font from a sans-serif font family. The third line of text shows a font setting that specifies a bold font weight, 14-point font size, and a font from a monospace font family:

An image showing text with different font property settings.

See also

CSSStyleDeclaration
currentStyle
defaults
runtimeStyle
style
CSS Values and Units Reference

 

 

Show:
© 2014 Microsoft. All rights reserved.