Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Units and Values

The ch, ex, cap, ic, lh and rlh units

Reference for CSS font-relative units ch, ex, cap, ic, lh and rlh: sizes based on glyph widths, heights and line height, with examples and caveats.

Besides em and rem, CSS has a family of units that measure against details of the current font or line height. They let a layout follow the typography instead of fixed pixel values: a text column that fits about 60 characters, a box that is exactly three lines tall, or an icon as tall as a capital letter.

  • ch is the advance width of the digit 0 in the element's font.
  • ex is the x-height, roughly the height of a lowercase x.
  • cap is the cap height, the height of capital letters.
  • ic is the advance of the CJK water ideograph (ๆฐด), a measure for East Asian text.
  • lh is the computed line-height of the element.
  • rlh is the computed line-height of the root element.
CSS
article p {
  max-width: 65ch;
  margin-block: 1lh;
}

Try it

Readable line length and line-based spacing

Setting the width in ch ties the line length to the text itself, so it stays comfortable if the font size changes.

Syntax

CSS
<length> = <number>ch | <number>ex | <number>cap | <number>ic
         | <number>lh | <number>rlh
         | <number>rch | <number>rex | <number>rcap | <number>ric
  • Reference: metrics of the element's used font (ch, ex, cap, ic) or its line height (lh); the r versions use the root element's font and line height.
  • Applies to: any property that accepts a <length>.
  • Animatable: yes, as part of a length.
  • Fallbacks: if a font lacks the needed metric, the browser estimates it, for instance ch as half of 1em and ex as half of 1em.

Values

Value Description
ch Width of "0" in the element's font.
ex x-height of the element's font.
cap Cap height (height of capital letters).
ic Width of the CJK water ideograph (ๆฐด).
lh Used line height of the element.
rlh Line height of the root element.
rch, rex, rcap, ric The same metrics, taken from the root element.

Usage notes

  • Measure for body text. max-width: 60ch to 75ch is a good range for paragraphs. In proportional fonts "0" is often wider than average letters, so a 65ch line holds more than 65 letters.
  • Monospace forms. In monospace fonts ch is the exact width of every character, which is handy for code blocks and inputs such as width: 6ch for a PIN.
  • Vertical rhythm. 1lh as a margin or padding keeps spacing in step with the line height. Remember that lh depends on the line height of the element it is used on.
  • ex and cap for icons. An inline icon sized 1cap lines up with capital letters; 1ex matches lowercase.
  • Font loading matters. The values change when a web font replaces the fallback font, which can cause layout shift.
  • Mind inheritance. lh follows the element's own computed line height; if it is normal, the value depends on the font and may differ between browsers.

Browser support

ch and ex are supported everywhere. cap, ic, lh, rlh and the root-metric variants are newer: check a compatibility table before depending on them, and provide a fallback such as 1.5em for 1lh.