Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to change style/class of an element using JavaScript ?
Next article icon

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

Last Updated : 25 Dec, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

object.style.fontWeight = "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.

Example:

HTML




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

Output:

Before Click the Button:

After Click the Button:

Supported Browsers:

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


Next Article
How to change style/class of an element using JavaScript ?

V

vkash8574
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Questions

Similar Reads

  • How to change the text of a label using JavaScript ?
    Changing the text of a label using JavaScript involves selecting the label element and updating its textContent or innerHTML property. This allows you to modify the displayed text dynamically, often in response to user interactions or changes in data, enhancing interactivity and responsiveness. Belo
    2 min read
  • How to change font-weight of a canvas-type text using Fabric.js?
    One can change the font-weight of a canvas-type using Fabric.js which adds versatility and style to the web applications and graphic design. It provides an efficient method to manipulate text properties such as font weight dynamically, which enhances the presentation and readability of the text elem
    3 min read
  • How to change style/class of an element using JavaScript ?
    In this article, we will learn how we can change the style/class of an element. If you want to build a cool website or app then UI plays an important role. We can change, add or remove any CSS property from an HTML element on the occurrence of any event with the help of JavaScript. There are two com
    4 min read
  • Allow users to change font size of a webpage using JavaScript
    If you have seen some websites, especially some Indian government portals, you would have noticed three small buttons at the top rightmost corner of the page looking something like this: -A A A+. These buttons generally allow website users to change the font size of the entire page or a certain port
    3 min read
  • JavaScript - How to Change the Content of a <Textarea> ?
    Here are the various methods to change the content of a textarea using JavaScript. 1. Using value PropertyThe value property is the most common method to change or retrieve the content of a <textarea>. [GFGTABS] HTML <textarea id="myTextarea">Initial content</textarea>
    2 min read
  • How to align text content into center using JavaScript ?
    In this article, we will align the text content into the center by using JavaScript. We use HTML DOM style textAlign property to set the alignment of text. The DOM style textAlign property is pretty much similar to the text-align property in the CSS, and the Dom textAlign property returns the horizo
    1 min read
  • How to set font size based on window size using JavaScript ?
    Given an HTML document and the task is to change the font-size based on the size of the window with the help of JavaScript. Approach 1: First convert the document element font sizes to em or % by using a function.Call this function on every resize of the window. It will change the font size based on
    1 min read
  • How to Create Text Animation Effect using JavaScript ?
    Creating text animations in JavaScript can add an extra layer of interactivity and engagement to a website or application. By using JavaScript, we can create text that moves, fades, changes color, or transforms in other ways. Animating text can also help convey important information or messages in a
    2 min read
  • How to change font style using drop-down list in JavaScript ?
    To change or set a font style for certain text, the fontFamily CSS property needs to be changed. The fontFamily property sets or returns a list of font-family names for text in an element. Syntax: object.style.fontFamily = "font" To change the font style by option dropdown: The font values can be pa
    2 min read
  • How to Change Text Inside all HTML Tags using JavaScript ?
    In this article, we will learn how to change the text content inside all HTML tags using JavaScript. This skill is valuable when you need to dynamically modify the text displayed on a web page. which can be useful for various scenarios like updating content, internationalization, or creating dynamic
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences