![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Style fontWeight Property
The HTML DOM fontWeight property is used for setting or returning the thickness of text characters of an element.
Following is the syntax for −
Setting the fontWeight property −
object.style.fontWeight = "normal|lighter|bold|bolder|value|initial|inherit"
The above properties are explained as follows
Value | Description |
---|---|
normal | Thisis the default and doesn’t make any changes to font. |
lighter | Fontis lighter |
bold | Setsthe font to bold which is thicker than lighter. |
bolder | Setsthe font to bolder which is thicker than bold. |
100 200 300 400 500 600 700 800 900 | Givesa range of values depicting light to bold characters. Normal=400,700=Bold. |
initial | Forsetting this property to initial value. |
inherit | Toinherit the parent property value |
Let us look at an example for the fontWeight property −
Example
<!DOCTYPE html> <html> <head> <style> #demo2,#demo1 { font-family: 'times new roman'; font-size: 25px; } </style> <script> function changeFontWeight() { document.getElementById("demo1").style.fontWeight="bold"; document.getElementById("demo2").style.fontWeight="bold"; document.getElementById("Sample").innerHTML="The font weight has been changed for the above paragraphs"; } </script> </head> <body> <div id="demo1" >This is demo text</div> <div id="demo2">This is demo text</div> <p>Change the font weight for the text inside above divs by clicking the below button</p> <button onclick="changeFontWeight()">Change font Weight </button> <p id="Sample"></p> </body> </html>
Output
On clicking the “Change font Weight” button −
Advertisements