CSS font-size Property

CSS font-size property specifies the size of the font.

Usages

The following table outline the usages and version history of this property.

Default value: medium
Applies to: All elements
Inherited: Yes
Version: CSS1
JavaScript Syntax: object.style.fontSize = "22px"

Syntax

Here is a syntax for the CSS font-size property

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

Property Values

The following table describes the values of this property.

Value Description
medium default. Browser displays as medium font size
length Browser displays as length value (expressed in px, em, etc..) of font size
percentage Browser displays as percentage value of font size
smaller, larger Browser displays one font-size larger or smaller than its parent element font size
For example. If the parent element has a font size of medium, a child element with a defined relative size of smaller will set the font size equal to smaller for the child element.
xx-small
x-small
small
medium
large
x-large
xx-large
Browser displays predefined font-sizes ranging from xx-small to xx-large size
initial Sets default value of this property
inherit Inherits this property from its parent element

Examples

The example below shows to sets font size such as medium, length, percentage, smaller, large values.

 p.one {   font-size: medium; } p.two {   font-size: 20px; } p.three {   font-size: 80%; } div.four {   font-size: medium; } p.four {   font-size: smaller; } p.five {   font-size: large; }

Browser Compatibility

  • Google Chrome 1+
  • Mozilla Firefox 1+
  • Internet Explorer 5.5+
  • Opera 7+
  • Safari 1+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.