Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

font-size (CSS property)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
Spec
Inherited Initial Version
Yes medium CSS1, 2
font-size: { absolute-size | relative-size | length | percentage | inherit } ;

Example

These style rules set the font size for paragraphs to be 80% of the parent element’s font size for screen output, and to be ten points for print output:

@media screen {
  p {
    font-size: 80%;
  }
}
@media print {
  p {
    font-size: 10pt;
  }
}

Try it yourself!View all demos

Description

This property specifies the font size to be applied to the text content of an element.

Value

An absolute size (sometimes referred to as a T-shirt size) is specified using one of the following keywords:

  • xx-small
  • x-small
  • small
  • medium
  • large
  • x-large
  • xx-large

The exact sizes to which those keywords map aren’t defined, but each one in the list above must be larger than or equal to the keyword that precedes it. User agents are recommended never to map any of those keywords to a physical size that’s less than nine pixels for screen use.

A relative size is specified using one of the following keywords:

  • smaller
  • larger

Those keywords will make the font size smaller or larger than the inherited value, by some factor that isn’t exactly defined. Most modern browsers seem to use a factor of 1.2, but the result may be adjusted to match a table of font sizes.

A length specified with a unit of em or ex refers to the computed font size that’s inherited from the parent element. This also applies to percentages.

Negative length values and percentages are illegal.

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

Internet Explorer for Windows up to and including versions 5.5 use an initial value of small, rather than medium.

Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.

User-contributed notes

ID:
#1
Date:
Thu, 06 Dec 2007 06:58:20 GMT
Contributed by:
achtungbaby

This section could probably have some additional info on the pros and cons of font-sizing using keywords, ems or percentages. Developers are actually all over the spectrum on this issue, most seeming to go with sizing with em's. Yahoo swears by percentages...

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters