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.
chis the advance width of the digit0in the element's font.exis the x-height, roughly the height of a lowercasex.capis the cap height, the height of capital letters.icis the advance of the CJK water ideograph (ๆฐด), a measure for East Asian text.lhis the computedline-heightof the element.rlhis the computedline-heightof the root element.
article p { max-width: 65ch; margin-block: 1lh; }
Try it
Setting the width in ch ties the line length to the text itself, so it stays comfortable if the font size changes.
Syntax
<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); therversions 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
chas half of1emandexas half of1em.
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: 60chto75chis a good range for paragraphs. In proportional fonts "0" is often wider than average letters, so a65chline holds more than 65 letters. - Monospace forms. In monospace fonts
chis the exact width of every character, which is handy for code blocks and inputs such aswidth: 6chfor a PIN. - Vertical rhythm.
1lhas a margin or padding keeps spacing in step with the line height. Remember thatlhdepends on the line height of the element it is used on. exandcapfor icons. An inline icon sized1caplines up with capital letters;1exmatches lowercase.- Font loading matters. The values change when a web font replaces the fallback font, which can cause layout shift.
- Mind inheritance.
lhfollows the element's own computed line height; if it isnormal, 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.
Related
emandremโ font-size-relative unitsline-heightfont-size-adjustโ keeps x-height steady across fonts- Lesson: CSS Units