Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
HTML and CSS
CSS Reference
Attributes
Font and Text
 fontSize Property
font-size Attribute | fontSize Property

Sets or retrieves a value that indicates the font size used for text in the object.

Syntax

HTML { font-size : sSize }
Scripting[ sSize = ] object.style.fontSize

Possible Values

sSizeString that specifies or receives one of the following values.
absolute-sizeSet of keywords that indicate predefined font sizes. Named font sizes scale according to the user's font setting preferences. Possible values include the following: xx-small, x-small, small, medium, large, x-large, xx-large.
relative-sizeSet of keywords that are interpreted as relative to the font size of the parent object. Possible values include the following: larger, smaller.
lengthFloating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px). For more information about the supported length units, see the CSS Length Units Reference.
percentageInteger, followed by a percent (%). The value is a percentage of the parent object's font size. In Microsoft Internet Explorer 3.0, the value is calculated as a percentage of the default font size.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of medium. The Cascading Style Sheets (CSS) attribute is inherited.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are not supported in IE8 mode. For more information, see About Dynamic Properties.

Remarks

As of Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, the default value for this property is small, not medium.

Negative values are not allowed. Font sizes using the proportional "em" measure are based on the font size of the parent object.

Possible length values specified in a relative measurement, using the height of the element's font (em) or the height of the letter "x" (ex), are supported in Internet Explorer 4.0 and later.

Examples

The following examples use the font-size attribute and the fontSize property to change font characteristics.

This example sets the font size on several paragraphs using different size values.

<STYLE>
   BODY{font-size: 10pt }
   .P1 {font-size: 14pt }
   .P2 {font-size: 75% }
   .P3 {font-size: xx-large }
   .P4 {font-size: larger }
</STYLE>
This feature requires Microsoft Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

This example uses inline scripting to set the font size to 14pt when an onmouseover event occurs.

<DIV STYLE="font-size:12pt" onmouseover="this.style.fontSize='14pt'">
:
</DIV>
This feature requires Microsoft Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1) World Wide Web link.

Applies To

A, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FORM, hn, HTML, I, INPUT type=button, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
New default value for font-size is "medium," not "small"      davishank   |   Edit   |  
The topic "font-size Attribute | fontSize Property" gets the new default value for font-size wrong. It should read "As of Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, the default value for this property is medium, not small."

This change was made to correct a well-known problem with scaling pages from the Text Size commands on the IE View menu.

The "larger" and "smaller" commands are mapped to the HTML relative font-size keywords of the same names. They instruct the browser to rescale the font-size of text relative to its container's font-size setting. If the container's font-size is set in scalable em or percentage units, then the text is rescaled relative to the font-size setting of the container's parent element.

By contrast, the "smallest," "medium" and "largest" Text Size options are mapped to HTML keywords for absolute font sizes. These depend upon the default fonts selected in the user's browser preferences, and the browser's internal font scaling algorithms.

In IE 6 not running under the "standards-compliant" doctype, and in earlier Internet Explorer versions, the default browser text-size was not mapped to the HTML absolute font-size keyword "medium," but rather to the absolute keyword "small."

Cf. "CSS Enhancements in Internet Explorer 6"
http://msdn.microsoft.com/en-us/library/bb250395(VS.85).aspx#cssenhancements_topic2
which gets the new default property "medium" right:
But Wait, There Are More New Features
"When you use the !DOCTYPE declaration to switch on standards-compliant mode with Internet Explorer 6 or later, ..."
Keyword Values of the Font-size Property
"The medium value of the font-size property matches the default normal font size.
The keyword values of this property include xx-small, x-small, small, medium, large, x-large, and xx-large.
With earlier versions of Internet Explorer, these values are not defined intuitively. The medium value is not the default normal font size; small is the default."

And see also "CSS Discuss-Wiki, Using Keywords"
http://css-discuss.incutio.com/?page=UsingKeywords
which explains the need for this change as follows:
"...Internet Explorer 6 in Quirks Mode and earlier Internet Explorer versions treat 'small' rather than 'medium' as the browser default, and each of the other keyword sizes correspondingly larger. As a consequence, authors using keywords should ensure that their documents are rendered in Standards Mode, and understand that early Internet Explorer versions will not size them the same as current browser versions."
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker