HTML DOM Style fontVariant Property


The HTML DOM Style fontVariant property is used for setting or returning if the font should be converted to small caps or not. In small caps all the lowercase letters are converted to uppercase with their size same as lowercase letters. Uppercase letters remain unaffected.

Following is the syntax for −

Setting the fontVariant property −

object.style.fontVariant = "normal|small-caps|initial|inherit"

The above property values are explained as follows −

Value
Description
normal
Thefont is set to normal and this is the default value.
small-caps
Itdisplays the form in small capital letters.
initial
Forsetting this property to initial value.
inherit
Toinherit the parent property value

Let us look at an example for the fontVariant propert −

Example

 Live Demo

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

Output

On clicking the “Change font Variant” button −

Updated on: 24-Oct-2019

17 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements