HTML DOM Style fontStyle Property


The HTML DOM Style fontStyle property is used for setting or returning the font style of the text. It is used to specify normal, italic or oblique style for an element’s text.

Following is the syntax for −

Setting the fontStyle property −

object.style.fontStyle = "normal|italic|oblique|initial|inherit"

Let us look at an example for the fontStyle property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #demo2,#demo1 {
      font-family: 'times new roman';
      font-size: 25px;
   }
</style>
<script>
   function changeFontStyle() {
      document.getElementById("demo1").style.fontStyle="italic";
      document.getElementById("demo2").style.fontStyle="italic";
      document.getElementById("Sample").innerHTML="The font style has been changed for the above    paragraphs.";
   }
</script>
</head>
<body>
   <div id="demo1" >This is demo text 1</div>
   <div id="demo2">This is demo text 2</div>
   <p>Change the above divs font style by clicking the below button</p>
   <button onclick="changeFontStyle()">Change fontStyle </button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change fontStyle” button −

Updated on: 24-Oct-2019

33 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements