fontWeight Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:fontWeight

Description

The fontWeight property sets or gets how thick or thin characters of text.

Property Values

Value Description
normal Font is normal. This is 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.

Technical Details

Item Value
Default Value: normal
Return Value: A String, representing the boldness of the font
CSS VersionCSS1

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="font-weight:bold">This is a paragraph.</p>

<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {// w ww  .  j ava  2s  . com
    document.getElementById("myP").style.fontWeight = '900';
}
</script>

</body>
</html>

Related Tutorials