This topic has not yet been rated - Rate this topic

fontWeight Property

Gets the numeric weight of the font of the object.

Syntax

HTML N/A
Scripting [ nWeight = ] object.currentStyle.fontWeight

Possible Values

nWeight Integer that receives one of the following values.
100
Font is at least as light as the 200 weight.
200
Font is at least as bold as the 100 weight and at least as light as the 300 weight.
300
Font is at least as bold as the 200 weight and at least as light as the 400 weight.
400
Default. Font is normal.
500
Font is at least as bold as the 400 weight and at least as light as the 600 weight.
600
Font is at least as bold as the 500 weight and at least as light as the 700 weight.
700
Font is bold.
800
Font is at least as bold as the 700 weight and at least as light as the 900 weight.
900
Font is at least as bold as the 800 weight.

The property is read-only. The property has a default value of 400. The Cascading Style Sheets (CSS) attribute is not 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

The fontWeight property of the currentStyle object is read-only. To set the value, use the fontWeight property of the style object. Unlike the style object, the fontWeight property of the currentStyle object only returns numeric values.

The values for fontWeight are mapped to specific font variations, depending on the fonts that are installed on the user's computer. In many cases, the user cannot see the difference between different fontWeight settings because the system chooses the closest match.

Example

The following example demonstrates how to set the fontWeight property of a P element. The script reads the fontWeight property of the currentStyle object and displays the value in a SPAN element.


<body onload="setInterval('s1.innerText = p1.currentStyle.fontWeight',200)">

<p id="p1">Click the buttons below.</p>

<button onclick="p1.style.fontWeight='lighter';">Lighter</button>
<button onclick="p1.style.fontWeight='normal';">Normal</button>
<button onclick="p1.style.fontWeight='bold';">Bold</button>
<button onclick="p1.style.fontWeight='bolder';">Bolder</button>

<br>Current Weight: <span id="s1"></span>

</body>

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

Standards Information

There is no public standard that applies to this property.

Applies To

A, ADDRESS, 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, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

See Also

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ