Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Typography

The font-size property

Reference for the CSS font-size property: set text size with px, rem, em, percentages, keywords and clamp(), with accessibility advice and live examples.

The font-size property sets the size of text. It also sets the meaning of the em unit for the element: 1em equals the element's own font size, so many other measurements (padding, margins, widths) can scale with the text.

Most browsers default to a font size of 16px for body text, but users can change that in their settings. Good CSS respects that choice by using relative units such as rem.

CSS
html { font-size: 100%; }
h1 { font-size: 2.5rem; }
small { font-size: 0.875em; }

Try it

Font-size units

Syntax

CSS
font-size: <absolute-size> | <relative-size> | <length-percentage [0,โˆž]> | math;
/* <absolute-size> = xx-small | x-small | small | medium | large | x-large | xx-large | xxx-large */
/* <relative-size> = larger | smaller */
  • Initial value: medium
  • Applies to: all elements and text, plus ::first-letter, ::first-line and ::placeholder
  • Inherited: yes (the computed size is inherited)
  • Animatable: yes, as a length
  • Computed value: an absolute length

Values

Value Description
<length> px, rem, em, vw, ch and so on. em here means the parent's font size.
<percentage> A percentage of the parent's font size.
xx-small to xxx-large Keyword sizes from a table that scales with the user's default size. medium is the default.
larger, smaller One step above or below the parent's size.
math A size suited to nested math content. Rarely used.

Usage notes

  • Prefer rem for text. A rem value follows the root font size, so a user who raised their default text size gets bigger text. Fixed px sizes still scale with browser zoom, but ignore a changed default size.
  • em compounds. Because em and % refer to the parent, nested elements multiply: a list inside a list at 0.9em shrinks twice. Use rem to avoid this.
  • Do not shrink the root. html { font-size: 62.5% } is a common trick, but it makes every unset size small. 100% is safer.
  • Fluid sizes. clamp(min, preferred, max) gives text that grows with the viewport but stays in a safe range. Add a rem part to the preferred value (for example 1rem + 1vw) so zoom still works.
  • Readable minimums. Body text below about 16px hurts readability, particularly on touch screens.
  • Mobile text inflation. Some mobile browsers boost small text in wide layouts; use viewport meta and fluid layouts rather than fighting it.
  • Browser minimums. Browsers may enforce a minimum size in settings, which overrides very small values.

Browser support

Supported in every browser.