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.
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%)`.
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.
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 →
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.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
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.