Style fontWeightProperty
Style Object
Definition and Usage
The fontWeight property sets or returns the weight of the font.
Syntax
Set the fontWeight property:
Object.style.fontWeight="value"
Return the fontWeight property:
Object.style.fontWeight
| Value | Description |
|---|---|
| normal | Default. The font is normal. |
| lighter | Defines a thinner font. |
| bold | Defines bold. |
| bolder | Defines a bolder font. |
| 100 200 300 400 500 600 700 800 900 |
Defines characters from thin to thick. 400 is equivalent to normal, 700 is equivalent to bold. |
| inherit | The value of the fontWeight property is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the fontWeight property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Change the font weight:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font weight</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font weight</button>
</body>
</html>
Try it yourself »
Style Object Other Extensions