O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

font-size

Values:

xx-small | x-small | small | medium | large | x-large | xx-large | smaller | larger | <length> | <percentage>

Initial value:

medium

Applies to:

All elements

Inherited:

Yes

Percentages:

Calculated with respect to the parent element’s font size

Computed value:

An absolute length

Description:

Defines the size of the font. The size can be defined as an absolute size, a relative size, a length value, or a percentage value. Negative length and percentage values are not permitted. The dangers of font-size assignment are many and varied, and points are particularly discouraged in web design, as there is no certain relationship between points and the pixels on a monitor. It’s a matter of historical interest that because of early misunderstandings, setting the font-size to medium led to different results in early versions of Internet Explorer and Navigator 4.x. Some of these problems are covered in Chapter 5 of CSS: The Definitive Guide, third edition (O’Reilly); for further discussion, refer to http://style.cleverchimp.com/. For best results, authors are encouraged to use either percentages or em units for font sizing. As a last resort, pixel sizes can be used, but this approach has serious accessibility penalties because it prevents users from resizing text in IE/Win, even when it is too small to read comfortably. Most other browsers allow users to resize text regardless of how it has been sized.

Examples:

h2 {font-size: 200%;} code {font-size: 0.9em;} p.caption {font-size: 9px;} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required