Style fontWeight attribute

Definition and usage

fontWeight Set or return the thickness of the text characters.

See also:

CSS Tutorial:CSS ƙasaar

CSS Reference Manual:font-weight attribute

HTML DOM Reference Manual:font attribute

Instance

Example 1

Set the font weight of the <p> element to "900":

document.getElementById("myP").style.fontWeight = "900";

Try it yourself

Example 2

Demonstration of possible values:

var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("myP").style.fontWeight = listValue;

Try it yourself

Example 3

Return the font weight of the <p> element:

alert(document.getElementById("myP").style.fontWeight);

Try it yourself

Syntax

Return fontWeight attribute:

object.style.fontWeight

Set fontWeight attribute:

object.style.fontWeight = "normal|lighter|bold|bolder|value|initial|inherit"

Attribute value

Value Description
normal The font is normal. Default.
lighter The font is thinner.
bold The font is bold.
bolder The font is thicker.
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

Define the character from thin to bold.

400 is the same as normal, 700 is the same as bold.

initial Sets this property to its default value. See initial
inherit Inherits this property from its parent element. See inherit

Technical details

Default value: normal
Return value: string value, indicating the font weight.
CSS version: CSS1

browser supports

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
ƙasaar ƙasaar ƙasaar ƙasaar ƙasaar