CKTIS / CSS
ex — the font x-height unit
The ex length unit refers to the x-height of the first available font. It lets dimensions follow font metrics, but does not represent a fixed pixel count or always equal half an em.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
<number>exex is a font-relative length unit. 1ex equals the used x-height of the element’s first available font—often the height of a lowercase “x”, although the unit exists even for fonts without that character. Write the number directly before the unit, without a space, for example 2ex.
Unlike em, which is based on font-size, ex depends on font metrics. When determining the x-height is impossible or impractical, the browser must assume 0.5em; this is not a general conversion rule. Changing the font can change the length of 1ex even when font-size stays unchanged.
In font-size and other font-affecting properties, the unit refers to the parent’s metrics. If the element has no parent, metrics corresponding to the initial values are used. This prevents a font’s size from depending on itself.
The example creates a rectangle with a width of 10ex and a height of 1ex. Both dimensions use the same metrics, so their ratio is 10, allowing for measurement rounding. Exact pixel dimensions depend on the selected font.
Examples
<!doctype html>
<meta charset="utf-8">
<title>ex</title>
<style>
.bar {
font: 32px serif;
width: 10ex;
height: 1ex;
background: teal;
}
</style>
<div class="bar"></div>Result
A teal rectangle whose CSS width is ten times its CSS height; exact pixel dimensions depend on the selected font.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.