← All stories
● Covered by 1 source · 1 reportLow impact1 neutral

Using `ch` and `ex` CSS Units for Text-Based Layouts Instead of Pixels

🔄 Updated 1h ago
New to BrevFeed? We gather this story from every outlet covering it into one summary — ranked by real-world impact, not just the latest headline — so you never miss what matters. What is BrevFeed? →

Key points

  • CSS pixels (`px`) do not always correspond to physical device pixels.
  • `ch` unit measures width based on the '0' character.
  • `ex` unit measures height based on a lowercase 'x' character.
  • Using `ch` and `ex` can improve readability and proportionality for text-heavy designs.

The Inaccuracy of Pixels in CSS

In CSS, the `px` unit does not consistently represent a single physical device pixel. On high-density displays, one CSS pixel can span multiple physical pixels. Similarly, other absolute units like `cm` often do not correspond to their real-world physical measurements on screens. CSS units are designed to be perceptual, meaning `16px` should appear roughly the same size across various devices at typical viewing distances.

Adopting `ch` for Widths

For text-centric layouts, basing element widths on character size can enhance readability. The `ch` unit in CSS measures the advance measure of the '0' (zero) character of the font. This allows for setting content widths that are proportional to the text itself, ensuring a consistent reading experience regardless of screen size or device. An example implementation sets a main content width to `min(75ch, 100%)`.

Utilizing `ex` for Heights and Spacing

While `ch` is suitable for horizontal measurements, the `ex` unit can be used for vertical spacing. The `ex` unit represents the x-height of the current font, typically the height of a lowercase 'x'. This allows for padding and margins to be set in proportion to the text's vertical dimensions, maintaining visual harmony within text-heavy elements.

Contextual Unit Selection

The choice of CSS unit depends on the specific design goal. While `px` remains a valid and widely used unit, `ch` and `ex` offer advantages for creating layouts that adapt more gracefully to different viewing environments, especially for content primarily composed of text. The developer notes this is an experimental approach, not a universal replacement for `px`.

✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →

The daily brief

One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.

One email a day. Unsubscribe in one click, any time.

Today's brief

Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.

~7 min · 6 stories · Aug 23

▶ Play today's brief Listen on Spotify

New every morning, and the back catalogue is archived by date.

Reporting from

A developer is experimenting with using `ch` and `ex` CSS units for layout, particularly for text-based content, instead of `px` units. This approach aims to create more perceptually consistent layouts across different devices and screen sizes by basing measurements on character width and height.