HTML | DOM Style fontWeight Property

The fontWeight property is used to set or return how thick or thin characters in a word should appear.

Syntax:

  • It returns the fontWeight property.

    object.style.fontWeight
  • It sets the fontWeight Property.

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

Property Values:

Value Description
normal Default value of font
lighter Lighter than normal
bold Bolder than normal
bolder Bolder than bold
value Define from 100 to 900 where 400 is normal value
initial Set to its default
inherit Inherit property from parent element

Return value: Return the boldness of the font of the string.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style fontWeight Property </title>
</head>
  
<body>
    <center>
        
        <!-- Property for p tag. -->
        <p style="color: green;
                  width: 100%;
                  font-size: 30px;
                  font-weight: bold;"
           id="sudo">
            GeeksForGeeks
        </p>
  
        <h2>DOM Style fontWeight Property </h2>
        <br>
        <button type="button" onclick="myGeeks()">
            Click to change
        </button>
  
        <script>
            function myGeeks() {
                
                //  Set property for "p" tag form
                //  'bold' to 'lighter'.
                document.getElementById(
                  "sudo").style.fontWeight = "lighter";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

  • Before click on button:
  • After click on button:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style fontWeight Property </title>
</head>
  
<body>
    <center>
        <p style="color: green;
                  width: 100%; 
                  font-size: 30px;" 
           id="sudo">
            GeeksForGeeks
        </p>
  
        <h2>DOM Style fontWeight Property </h2>
        <br>
        <button type="button" onclick="myGeeks()">
            Click to change
        </button>
  
        <script>
            function myGeeks() {
                
                //  Set property from normal to bold.
                document.getElementById(
                "sudo").style.fontWeight = "bold";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

  • Before click on button:
  • After click on button:

Example-3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style fontWeight Property </title>
</head>
  
<body>
    <center>
        <p style="color: green;
                  width: 100%; 
                  font-size: 30px;"
           id="sudo">
            GeeksForGeeks
        </p>
  
        <h2>DOM Style fontWeight Property </h2>
        <br>
        <button type="button" onclick="myGeeks()">
            Click to change
        </button>
  
        <script>
            function myGeeks() {
                
                //  Set property bolder.
                document.getElementById(
                  "sudo").style.fontWeight = "bolder";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

  • Before click on button:
  • After click on button:

Example-4:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style fontWeight Property </title>
</head>
  
<body>
    <center>
        <p style="color: green;
                  width: 100%; 
                  font-size: 30px;"
           id="sudo">
            GeeksForGeeks
        </p>
  
        <h2>DOM Style fontWeight Property </h2>
        <br>
        <button type="button" onclick="myGeeks()">
            Click to change
        </button>
  
        <script>
            function myGeeks() {
                
                //  Set font using values.
                document.getElementById(
                  "sudo").style.fontWeight = "1000";
            }
        </script>
    </center>
</body>
  
</html>                  

chevron_right


Output:

  • Before click on button:
  • After click on button:

Supported Browsers: The browser supported by HTML | DOM Style fontWeight Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.