CSS Reference ยท Typography
The font-size-adjust property
Reference for the CSS font-size-adjust property: keep text the same visual size when fallback fonts have different x-heights, with values and notes.
The font-size-adjust property keeps text looking the same size even when the font changes. Two fonts at 16px can look very different in size, because their lowercase letters have different heights relative to the font size. This ratio is called the aspect value; for the common case it is the x-height divided by the font size.
When the preferred font fails to load and a fallback is used, text can suddenly look larger or smaller. With font-size-adjust, the browser rescales whichever font is actually used so that its x-height matches the number you give.
body { font-family: "My Web Font", Verdana, sans-serif; font-size-adjust: 0.5; }
Try it
Compare the lowercase letters in the first pair with the second pair. With the adjustment, the two fonts get closer to the same x-height. The exact difference depends on the fonts installed on your device.
Syntax
font-size-adjust: none | [ ex-height | cap-height | ch-width | ic-width | ic-height ]?
[ from-font | <number [0,โ]> ];
- Initial value:
none - Applies to: all elements and text
- Inherited: yes
- Animatable: yes, as a number
- Computed value:
none, or the keyword and number as specified
Values
| Value | Description |
|---|---|
none |
No adjustment. The font-size is used as given. The default. |
<number> |
The aspect value to aim for, such as 0.5. The used size is font-size ร (number รท the font's own aspect value). |
from-font |
Use the aspect value of the first available font in the stack, so every fallback is scaled to match it. |
| metric keyword | ex-height (the default), cap-height, ch-width, ic-width or ic-height choose which measurement is matched. |
Usage notes
- Number or
from-font. A fixed number is predictable.from-fontis convenient with web fonts because you do not need to look up the value, but the first available font may itself be a fallback. - Typical values. Many fonts have an x-height ratio between about 0.45 and 0.55. Look up your main font's value or use
from-font. - It inherits. Setting it once on
bodyrescales text in every descendant. Child elements with a different font-size are still adjusted by the same number. - It changes layout. The adjusted size is used for text metrics, so line breaks and heights can differ slightly from an unadjusted version.
- Mixed-script text. The extra metric keywords are useful for East Asian text (
ic-width) and uppercase-heavy text (cap-height). - Fallback matching. Pair it with a good fallback stack, as described in
font-family, to reduce layout shifts when web fonts load.
Browser support
Number values are supported in current browsers. Support for from-font and the metric keywords is newer and not equal across browsers, so check a compatibility table before relying on them. Browsers without support simply ignore the property, so text stays readable.
Related
font-sizefont-familyfontโ note that the shorthand resets this property@font-faceโ related descriptors for web fonts- Lesson: Web Fonts, Fonts