HTML DOM Style fontSize Property


The HTML DOM Style fontSize property is used to set or return the size of font.

Following is the syntax for −

Setting the fontSize property −

object.style.fontSize = "value|initial|inherit"

The above properties are explained as follows −

Value
Description
xx-small
x-small
small
medium
large
x-large
xx-large
Forsetting the front size from one of value ranging from xx-small toxx-large.
smaller
Itdecreases the text font-size by one relative unit.
larger
Itincreases the text font-size by one relative unit.
length
Fordefining the font-size in legal length units.
%
Itsets the child element font size relative to % of the parentelement font size.
initial
Forsetting this property to initial value.
inherit
Toinherit the parent property value

Let us look at an example for the fontSize property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   li{
      font-size: 1.1em;
      background-color: snow;
      font-family: cursive;
   }
</style>
<script>
   function changeFontSize() {
      for(var i=0;i<3;i++){
         document.getElementsByTagName("li")[i].style.fontSize="xx-large";
      }
      document.getElementById("Sample").innerHTML="The font size for the above list is now set to xx-   large";
   }
</script>
</head>
<body>
   <ul>
      <li>This is list item 1.</li>
      <li>This is list item 2</li>
      <li>This is list item 3</li>
   </ul>
   <p>Change the above list items font size by clicking the below button</p>
   <button onclick="changeFontSize()">Change Font Size</button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change Font Size” button −

Updated on: 24-Oct-2019

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements