This topic has not yet been rated - Rate this topic

font-size Attribute | fontSize Property

Gets or sets a value that indicates the font size used for text in the object.

Syntax

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

Possible Values

sSize String that specifies or receives one of the following values.
absolute-size
Set 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-size
Set of keywords that are interpreted as relative to the font size of the parent object. Possible values include the following: larger, smaller.
length
Floating-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.
percentage
Integer, 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 supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Remarks

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

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.

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>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/font-size.htm

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>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/fontSize.htm

Standards Information

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

Applies To

A, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CSSStyleDeclaration, 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

Did you find this helpful?
(1500 characters remaining)

Community Additions

© 2013 Microsoft. All rights reserved.