Set Font Size with em using CSS



To set font size with pixels, use the em unit, with the font-size property.

1em = 16px

Example

You can try to run the following code to set font size with em

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         h1 {
            /* 30px/16 = 1.875em */
            font-size: 1.875em;
         }
      </style>
   </head>
   <body>
      <h1>This is demo heading</h1>
      <p>This is demo text.</p>
   </body>
</html>

Advertisements