skip to content

In CSS, what does the `ch` unit measure, and why is `max-width: 65ch` a common way to limit line length?

level: juniorimportance: nice to knowfreq 24%

answer

  1. one specific glyph, not an average
  2. the digit zero
  3. advance width, not ink width
  4. measure in characters, not pixels
  5. exact only in monospace

basics

~20 s

1ch is the advance width of the character 0 (zero) in the element's own font, so it scales with that font and its size. It approximates a character width, which makes it a convenient unit for capping the line length of body text.

solid answer

~50 s

`ch` is a font-relative CSS unit: `1ch` equals the advance width — the horizontal space consumed — of the `0` (zero) glyph in the element's current font. If the font provides no such measure, browsers fall back to `0.5em` in a horizontal writing mode. Because it is tied to the element's own font and font-size, a value like `max-width: 65ch` produces a measure that stays readable when the font changes or when the user enlarges their text, which a `px` max-width would not. The honest caveat: it is an approximation, not a character count. In a proportional font, digits are usually wider than typical lowercase letters, so `65ch` renders somewhat wider than 65 average characters; only in a monospaced font is the mapping exact. Its sibling `ex` measures the font's x-height — the height of a lowercase `x` — and is used for fine vertical alignment of inline decorations.

code

css · 8 lines
css
/* Line length stated in the terms the rule is about */
.prose { max-width: 65ch; }

/* Exact in a monospaced font: every glyph shares one advance */
.code-column { font-family: monospace; width: 80ch; }

/* ex is a vertical measure: the font's x-height */
.inline-icon { width: 1em; height: 1ex; }

go deeper

for a junior

Recall that 1ch is the width of the character 0 in the current font, and that max-width in ch is the idiomatic way to cap the line length of body text.

for a middle

Explain that ch is an advance width including side bearings, that the fallback is 0.5em when unmeasurable, and why the count is only exact in a monospaced font.

for a senior

Show why a ch-based measure survives font swaps and user text scaling where a px cap does not, and mention the small reflow risk when a web font with a different zero width finishes loading.

for a principal

Frame measure as a typographic contract in the design system: encode it once as a token so every prose surface agrees, rather than letting each team pick its own px column width.

## What ch is defined as `ch` is one of the font-relative length units in CSS. `1ch` equals the **advance measure of the `0` (U+0030 DIGIT ZERO) glyph** in the element's computed font — that is, how far the text cursor moves after rendering a zero, which includes the glyph's side bearings, not just the ink. If that measure cannot be determined — the font has no zero glyph, or the font is unavailable — the spec defines a fallback: `1ch` is `0.5em` in a horizontal writing mode. Because the reference is the element's *own* font at its *own* size, `ch` inherits two useful behaviours: change the font-family and the unit re-measures; change the font-size (or the user changes theirs) and the unit scales with it. ## Why it is used for line length Typographic guidance for body text is stated in characters per line — commonly somewhere around 45 to 75 — because eye movement and line-return accuracy degrade on very long lines. CSS has no "characters" unit, but `ch` is the closest available proxy: ```css .prose { max-width: 65ch; } ``` The advantage over `max-width: 700px` is that the constraint is expressed in the terms the rule is actually about. Swap the font, bump the font-size, or let a user enlarge their default text, and the column re-measures to keep roughly the same number of characters per line. A px cap silently becomes too many characters per line at small text and too few at large text. ## The caveat: ch is not a character count In a proportional (non-monospaced) font, characters have different widths, and digits are typically drawn on a wider, tabular-ish advance than average lowercase letters. So `65ch` of running prose usually fits **more** than 65 characters per line — the column is a bit wider than the naive reading suggests. Treat the number as a tuning knob you adjust by eye, not a literal count. In a monospaced font every glyph shares one advance width, so there `Nch` genuinely is N characters. That makes `ch` especially precise for code blocks, terminal-style layouts, and fixed-column alignment. ## ex, and the family it belongs to `ex` is the other classic font-relative unit: `1ex` is the **x-height** of the element's font — the height of a lowercase `x`, i.e. the body of the letters excluding ascenders and descenders. Its fallback when unmeasurable is also `0.5em`. `ex` is a vertical measure and is used for optical alignment of inline decorations: nudging an inline icon or a superscript so it lines up with the visual centre of the text rather than with the baseline or the full em box. ```css .inline-icon { width: 1em; height: 1ex; /* aligns to the body of the text, not the em box */ } ``` Both sit alongside `em` and `rem` in the font-relative family. The distinction: `em`/`rem` measure the declared font *size*, which is a number you chose; `ch` and `ex` measure something about the rendered *font itself*, which varies between typefaces at the same size. ## Practical notes - **Font loading.** Since `ch` depends on the font actually in use, a `ch`-sized column measured against a fallback font can shift slightly when the web font arrives, if the two fonts have different zero widths. - **Not just for max-width.** A `ch` value is a sensible width for an input that should hold a known number of digits — a postcode or a card-expiry field — because the reference glyph is literally a digit. Remember it is a visual hint only; the field's actual constraints live in the markup. - **Do not use it for vertical rhythm.** `ch` is a horizontal advance; heights belong to `em`, `rem`, `ex`, or line-based units. The interview-grade summary is short: `ch` is the width of a zero in the current font, it makes line-length limits self-adjusting instead of hard-coded, and it approximates rather than counts characters unless the font is monospaced.

  • Does max-width: 65ch guarantee 65 characters per line?
    Only in a monospaced font. In a proportional font the reference glyph — the digit zero — is usually wider than the average lowercase letter, so a 65ch column typically fits more than 65 characters of running prose. Treat the number as a tuning value you adjust by eye rather than a literal count.
  • Why choose ch over a px max-width for a text column?
    Because the constraint is really about characters per line, and `ch` tracks the element's actual font and size. Change the typeface, bump the font-size, or let a user enlarge their default text, and the column re-measures to keep a similar measure. A px cap drifts to too many characters at small sizes and too few at large ones.
  • What does ex measure and where would you use it?
    `1ex` is the x-height of the element's font — the height of a lowercase x, excluding ascenders and descenders. It is a vertical measure used for optical alignment: sizing or nudging an inline icon, bullet, or superscript so it aligns with the visual body of the text rather than the baseline or the full em box.

  • Says 1ch is the average character width of the font
  • Claims Nch always fits exactly N characters
  • Thinks ch measures the widest glyph, like M
  • Confuses ex with a horizontal width unit
  • Believes ch is relative to the root font like rem

context