You are here: Reference > JavaScript > client-side > style handling > properties > fontWeight

fontWeight style property

Browser support:
Specifies or returns the font weight of the text.
The currentStyle.fontWeight JavaScript property returns only integer values (100 - 900) in Internet Explorer.

Syntax:

object.fontWeight;
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: font-weight

Possible values:

The type of this property is string.
 One of the following values: 
normal
Font is normal.
bold
Font is bold.
bolder
Font is bolder.
lighter
Font is lighter.
100
Not bolder than 200 weight.
200
Not bolder than 300 weight.
300
Not bolder than 400 weight.
400
Font is normal.
500
Not lighter than 400 weight and not bolder than 600 weight.
600
Not bolder than 700 weight.
700
Font is bold.
800
Not lighter than 700 weight.
900
Not lighter than 800 weight.
inherit
Takes the value of this property from the computed style of the parent element.
Default: normal.

Example HTML code 1:

This example illustrates the use of the font-weight property:
<head>
    <style>
        .normal {
            font-weight: normal;
        }
        .bold {
            font-weight: bold;
        }
    </style>
</head>
<body>
    <span class="normal">font-weight: normal</span>
    <span class="bold">font-weight: bold</span>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the fontWeight property in JavaScript:
<head>
    <script type="text/javascript">
        function ChangeFont (selectTag) {            
            // Returns the index of the selected option
            var whichSelected = selectTag.selectedIndex;

            // Returns the selected options values
            var selectState = selectTag.options[whichSelected].text;

            var fontTest = document.getElementById ("fontTest");
            fontTest.style.fontWeight = selectState;
        }
    </script>
</head>
<body>
    <span id="fontTest">
        Sample multiline text <br />change it!
    </span>

    <br />
    <select onchange="ChangeFont (this);" size="7">
        <option />bold
        <option />bolder
        <option />lighter
        <option />normal
        <option />300
        <option selected="selected" />600
        <option />900
    </select>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content