font property
Specifies a combination of separate IHTMLCSSStyleDeclaration::font properties of the object. Alternatively, sets or retrieves one or more of six user-preference fonts.
Syntax
Integer value = object.put_font( v);Integer value = object.get_font(* p);
Property values
Type: BSTR
Up to six of the following space-delimited property values. Alternatively, sets or retrieves the six listed text fonts.
font-style (normal)
Any of the range of font-style values available to the IHTMLCSSStyleDeclaration::fontStyle property.
font-variant (normal)
Any of the range of font-variant values available to the IHTMLCSSStyleDeclaration::fontVariant property.
font-weight (normal)
Any of the range of font-weight values available to the IHTMLCSSStyleDeclaration::fontWeight property.
font-size (medium)
Any of the range of font-size values available to the IHTMLCSSStyleDeclaration::fontSize 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 (normal)
Any of the range of line-height values available to the IHTMLCSSStyleDeclaration::lineHeight property. When used with the IHTMLCSSStyleDeclaration::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 ("Times New Roman")
Any of the range of font-family values available to the IHTMLCSSStyleDeclaration::fontFamily 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.
String format
[[ font-style || font-variant || font-weight ]? font-size [ / line-height ]? font-family ]| caption | icon | menu | message-box | small-caption | status-bar
CSS information
Applies To | All elements |
Media | visual |
Inherited | 1 |
Initial Value | the 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 IHTMLCSSStyleDeclaration::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.
- 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 IHTMLCSSStyleDeclaration::font property is ignored.
- All specified values must appear in the correct order. Otherwise, the IHTMLCSSStyleDeclaration::font property is ignored.
- 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.
When you use the !DOCTYPE declaration to specify standards-compliant mode, the following conditions apply to this property.
- 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 IHTMLCSSStyleDeclaration::font property is ignored.
- All specified values must appear in the correct order. Otherwise, the IHTMLCSSStyleDeclaration::font property is ignored.
- In standards-compliant mode, the default font-size is small, not medium. If not explicitly set, font-size returns a point value.
Examples
This example displays three lines of text using different IHTMLCSSStyleDeclaration::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 IHTMLCSSStyleDeclaration::font setting that specifies a font from a serif font family. The second line of text shows a IHTMLCSSStyleDeclaration::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 IHTMLCSSStyleDeclaration::font setting that specifies a bold font weight, 14-point font size, and a font from a monospace font family:
Requirements
Minimum supported client |
Windows XP |
Minimum supported server |
Windows Server 2003 |
Header |
Mshtml.h |
IDL |
Mshtml.idl |
DLL |
Mshtml.dll |