font-size - HTML CSS CSS Property

HTML CSS examples for CSS Property:font-size

Description

The font-size CSS property sets the font size for the text content.

The following table summarizes the font-size Property.

Item Value
Default value: medium
Applies to:All elements
Inherited: Yes
Animatable: Yes.

Syntax

The syntax of the property is as follows:


font-size:     xx-small | 
               x-small | 
               small | 
               medium | 
               large | 
               x-large | 
               xx-large | 
               smaller | 
               larger | 
               length | 
               percentage | 
               initial | 
               inherit

Property Values

The following table describes the values of this property.

smaller and larger are size relative to its parent.

xx-small and xx-large are small to large size relative to each other.

Value Description
length A length value in px, pt, cm, em, etc. Negative values are not allowed.
percentage Sets the font size to a percent of the parent element's font size. Negative values are not allowed.
initialSets this property to its default value.
inherittake the value of its parent element font-size property.

The example below shows the font-size property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS font-size property</title>
  <style type="text/css">
    body {<!--from   www . j  a va2s  . c  o  m-->
      font-size: 14px;
    }
    h1 {
      font-size: 2em;
    }
    </style>
 </head>
 <body>
  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>
 </body>
</html>

Related Tutorials