Name

font-size

Values:

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

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:

This property sets 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 due to 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 ...

Get CSS Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.