Set the font weight for an element to "900":
document.getElementById("demo").style.fontWeight = "900";
Try it Yourself »
The fontWeight property sets or returns how thick or thin characters in a text should be displayed.
Property | |||||
---|---|---|---|---|---|
fontWeight | Yes | Yes | Yes | Yes | Yes |
Return the fontWeight property:
object.style.fontWeight
Set the fontWeight property:
object.style.fontWeight = "normal|lighter|bold|bolder|
value|initial|inherit"
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 |
Default Value: | normal |
---|---|
Return Value: | A String, representing the boldness of the font |
CSS Version | CSS1 |
A demonstration of possible values:
var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("demo").style.fontWeight = listValue;
Try it Yourself »
Return the font weight of an element:
alert(document.getElementById("demo").style.fontWeight);
Try it Yourself »
CSS tutorial: CSS Font
CSS reference: font-weight property
HTML DOM reference: font property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!