Javascript DOM CSS Style fontWeight Property

Introduction

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP">This is a paragraph.</p>

<button type="button" onclick="myFunction()">Set font weight</button>

<script>
function myFunction() {/*www. j  a  v  a2 s.  c  o  m*/
  document.getElementById("myP").style.fontWeight = "900";
}
</script>

</body>
</html>

The fontWeight property sets or gets how thick or thin text should be displayed.

Property Values

Value Description
normal Font is normal. default
lighter Font is lighter
boldFont 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.
inherit Inherits this property from its parent element.

The fontWeight property returns a String representing the boldness of the font.




PreviousNext

Related