Example
Set the font weight for a <p> element to "900":
document.getElementById("myP").style.fontWeight = "900";
Try it Yourself »
Definition and Usage
The fontWeight property sets or returns how thick or thin characters in a text should be displayed.
Browser Support
The fontWeight property is supported in all major browsers.
Syntax
Return the fontWeight property:
object.style.fontWeight
Set the fontWeight property:
object.style.fontWeight="normal|lighter|bold|bolder|value|initial|inherit"
Property Values
Value | Description |
---|---|
normal | Font is normal. This is default |
lighter | Font is lighter |
bold | Font is bold |
bolder | Font is bolder |
100 200 300 400 500 600 700 800 900 |
Defines from light to bold characters. 400 is the same as normal, and 700 is the same as bold |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | normal |
---|---|
Return Value: | A String, representing the boldness of the font |
CSS Version | CSS1 |
More Examples
Example
A demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("myP").style.fontWeight = listValue;
Try it Yourself »
Example
Return the font weight of a <p> element:
alert(document.getElementById("myP").style.fontWeight);
Try it Yourself »
Related Pages
CSS tutorial: CSS Font
CSS reference: font-weight property
HTML DOM reference: font property
< Style Object