Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

ch — a length unit based on the zero glyph

The ch unit measures length relative to the advance measure of the 0 glyph in the font being used. It helps size text-based layouts but does not represent a count of arbitrary characters.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

<number>ch

ch is a font-relative length unit. 1ch equals the advance measure of the 0 glyph (U+0030): its advance width or height along the inline axis, not the width of its visible outline. Write the number immediately before the unit, for example 10ch.

width: 60ch does not guarantee room for exactly 60 arbitrary characters. Proportional fonts give letters different widths. The value depends on the font, its size and settings, and on the writing mode and glyph orientation. The writing mode (writing-mode) determines the inline axis, and the glyph’s orientation affects its advance along that axis. Changing direction from ltr to rtl does not by itself change that advance. Unlike em, ch is not directly a multiple of the font size.

If the advance of 0 cannot be determined, the fallback is 0.5em; for upright vertical text with text-orientation: upright, it is 1em. When ch is used in font-size, it resolves against the parent element’s font metrics. If the element has no parent, as with the root element, it resolves against the initial font metrics.

The example sets the content width to 10ch and displays ten zeros in monospace. The expected match concerns glyph advances, not outlines. The actual pixel width depends on the local font.

Examples

<!doctype html>
<meta charset="utf-8">
<title>ch</title>
<style>
  .sample {
    font: 20px/1.5 monospace;
    writing-mode: horizontal-tb;
    letter-spacing: 0;
    width: 10ch;
    padding: 0;
    border: 0;
    background: #def;
  }
</style>
<div class="sample">0000000000</div>

Result

0000000000

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources