CSS font-size-adjust: How to Use It for Consistent Text Sizing
In this article
CSS font-size-adjust lets you preserve the visual size of text when the fallback font has a different aspect ratio (x-height) than your first-choice font. You use it by specifying a number (the aspect ratio of your preferred font) and the browser scales fallback fonts so their x-height matches, keeping text readable and layout stable.
What Is font-size-adjust and Why Does It Matter?
When you set font-family: 'Helvetica', Arial, sans-serif;, the browser uses Helvetica if available; otherwise it falls back to Arial. But not all fonts are created equal: some have tall lowercase letters (large x-height), others have short ones. The font-size sets the em square (roughly the height from the top of ascenders to the bottom of descenders), but the visual size of text is largely determined by the height of lowercase letters (x-height). A font with a small x-height looks smaller and harder to read at the same pixel size than one with a large x-height.
font-size-adjust solves this by adjusting the rendered size of fallback fonts so that their x-height matches the x-height of your first-choice font. This keeps headings and body text looking consistent even when the user's system lacks your preferred font.
How font-size-adjust Works
The property takes a unitless number that represents the ratio of the font's x-height to its font-size (the aspect value). For example, if a font has an x-height of 0.5 em, its aspect value is 0.5.
When you set font-size-adjust: 0.5, the browser will adjust the font-size of fallback fonts so that their x-height equals 0.5 times the original font-size. If the fallback font has a smaller x-height, it gets scaled up; if it has a larger x-height, it gets scaled down.
Here's a simple example:
p {
font-family: 'Verdana', 'Tahoma', sans-serif;
font-size: 16px;
font-size-adjust: 0.545; /* Verdana's aspect value */
}
If Tahoma is used instead of Verdana, the browser will compute Tahoma's aspect value (roughly 0.54) and adjust its font-size so the x-height matches what Verdana would have been. The result is that the text looks almost identical in size, even though the font is different.
How to Choose the Right Aspect Value
You can find the aspect value of a font by dividing its x-height by its font-size. Many fonts have known values, but you can measure them yourself using a tool like a font editor or by rendering text and measuring it with JavaScript.
If you don't know the exact value, you can estimate it:
- Fonts with large x-heights (like Verdana, Trebuchet MS) have aspect values around 0.5–0.55.
- Fonts with medium x-heights (like Arial, Helvetica) are around 0.45–0.5.
- Fonts with small x-heights (like Times New Roman, Georgia) are around 0.4–0.45.
For best results, use the aspect value of your primary font. If you're using a web font, you can often find its aspect value in its documentation or by measuring it.
Common Problems and Misconceptions
Misconception: font-size-adjust changes the font-size. It doesn't change the CSS font-size value; it changes the rendered size of the fallback font. The element still takes up the same space in the layout (unless you also adjust line-height), but the glyphs are scaled.
Problem: It doesn't work in all browsers. As of 2024, font-size-adjust is supported in Firefox, Safari, and Chrome (since version 109), but not in older Edge versions or some mobile browsers. You can use the @supports rule to provide a fallback:
@supports (font-size-adjust: 0.5) {
p { font-size-adjust: 0.5; }
}
Problem: It can cause layout shifts. Because the fallback font is scaled, its line height may change, causing text to overlap or leave extra space. You may need to adjust line-height or use a fixed line-height to keep things stable.
Comparison with Other Techniques
Other methods for consistent text sizing include:
- Using a web font with
font-display: swap– ensures the same font is always used, but adds loading time. - Setting a fallback font with a similar x-height – e.g., using Arial as a fallback for Helvetica, which are very similar.
- Using CSS
text-size-adjust– this is for mobile browsers to prevent font inflation, not for fallback consistency. - Using
font-sizewith media queries – adjusts size for different viewports, but doesn't handle font substitution.
font-size-adjust is unique because it actively corrects the visual discrepancy between fonts, rather than just hoping the fallback looks similar.
Practical Tips for Using font-size-adjust
- Use it on headings and body text where font consistency is critical.
- Combine it with a
font-familystack that includes fonts with similar aspect values to minimize the adjustment needed. - Test with multiple fallback fonts to ensure the adjustment doesn't cause clipping or overflow.
- Remember that
font-size-adjustis inherited, so you can set it on a parent element and it will apply to all children. - For the
font-size-adjustvalue, you can also use the keywordfrom-font(supported in some browsers) to automatically use the aspect value of the first available font in the stack.
Frequently Asked Questions
Does font-size-adjust affect the actual font-size value?
No, it only affects the rendered size of the glyphs. The computed font-size remains the same, which means the element's height (and line-height if not adjusted) stays the same. This can cause text to appear larger or smaller than the surrounding layout, so you may need to adjust line-height.
What is the default value of font-size-adjust?
The default is none, which means no adjustment is made. The browser uses the fallback font at its natural size.
Can I use font-size-adjust with web fonts?
Yes, you can use it with any font, including web fonts. If the web font is loaded, the aspect value of that font will be used (or you can specify it manually). If the web font fails to load, the fallback will be adjusted.
How do I find the aspect value of a font?
You can use a font editor like FontForge, or you can render text in a canvas and measure the height of lowercase letters (like 'x') relative to the font-size. Alternatively, many font documentation pages list the x-height.
Is font-size-adjust supported in all browsers?
As of 2024, it's supported in Firefox, Safari, and Chrome (109+). It is not supported in Internet Explorer or older Edge versions. Always use feature detection or provide a fallback.
Does font-size-adjust work with line-height?
No, it doesn't automatically adjust line-height. You may need to set a fixed line-height or use a unit like em to ensure spacing remains consistent.