Style fontWeight Attribute

Definition and Usage

fontWeight Sets or returns the text character's thickness degree of the property.

See also:

CSS Tutorial:CSS Font

CSS Reference Manual:font-weight Attribute

HTML DOM Reference Manual:font Attribute

Example

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

Returns the font weight of the <p> element:

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

Try It Yourself

Syntax

Return fontWeight property:

object.style.fontWeight

Set fontWeight property:

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 also initial.
inherit Inherits this property from its parent element. See also inherit.

Technical Details

Default value: normal
Return value: String value, indicating the font weight.
CSS Versions: CSS1

Browser Supports

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Suporta Suporta Suporta Suporta Suporta