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:
<!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
filter_none
Output:
- Before click on button:
- After click on button:
Example-2:
<!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
filter_none
Output:
- Before click on button:
- After click on button:
Example-3:
<!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
filter_none
Output:
- Before click on button:
- After click on button:
Example-4:
<!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
filter_none
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
Recommended Posts:
- HTML | DOM Style right Property
- HTML | DOM Style top Property
- HTML | DOM Style animationTimingFunction Property
- HTML | DOM Style transformOrigin Property
- HTML | DOM Style tableLayout Property
- HTML | DOM Style display Property
- HTML | DOM Style listStyleType Property
- HTML | DOM Style flexBasis Property
- HTML | DOM Style visibility Property
- HTML | DOM Style textAlignLast Property
- HTML | DOM Style outlineOffset Property
- HTML | DOM Style textIndent Property
- HTML | DOM Style flexDirection Property
- HTML | DOM Style columnRuleStyle Property
- HTML | DOM Style userSelect Property
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.



