Skip to content
Related Articles

Related Articles

Improve Article

How to change font-weight of a text using JavaScript ?

  • Last Updated : 25 Dec, 2020
Geek Week

In this article, we will set the font-weight of a text dynamically using JavaScript. Ti change the font weight dynamically, we use HTML DOM Style fontWeight property. 

Syntax: = "value"

Property Values:

  • normal: The font weight is the default value.
  • lighter: The font weight is the lighter than normal.
  • bold: The font weight is bolder than normal.
  • bolder:  The font weight is bolder than bold.
  • value:  It defines from 100 to 900 where 400 is normal value.
  • initial:  It sets to its default font weight.
  • inherit:  It inherits this property from its parent element.



<!DOCTYPE html>
        How to change font-weight of
        a text using JavaScript?
<body style="text-align: center;">
    <h1 style="color: green">
        How to change font-weight of
        <br>a text using JavaScript?
    <p id="sudo">Welcome to GeeksforGeeks</p>
    <button type="button" onclick="myGeeks()">
        Click to change
        function myGeeks() {
                .style.fontWeight = "bold";


Before Click the Button:

After Click the Button:

Supported Browsers:

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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :