Font metrics and layout stability
Definition and purpose
Fallback text can occupy different widths and line boxes from the final face, causing movement during a font swap. Font metrics describe quantities such as ascent, descent and line gap. CSS provides face-level overrides and size adjustment to align fallback characteristics more closely with a target.
Declare metric overrides
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @font-face { font-family: LessonMetrics; src: local("ByteMind Nonexistent Metrics Face 73"); size-adjust: 105%; ascent-override: 90%; descent-override: 20%; line-gap-override: 0%; } #a { font-family: LessonMetrics, serif; } </style> </head> <body> <p id="a">Sample line with fallback</p> </body></html>CSSOM retains the declared metrics; the unavailable face is not a rendering test.
Syntax and mental model
size-adjust scales the glyph outlines and metrics of an @font-face; ascent-override, descent-override and line-gap-override customize vertical metrics. By contrast, font-size-adjust is a property that can preserve a selected relative metric across fallback faces, such as x-height with its default metric. The numbers here are illustrative, not universal calibration. A fixed line-height gives a predictable line-box height in the simple single-line fixture but cannot guarantee matching text widths or eliminate layout shift. Calibrate with real target and fallback font data and measure layout before and after loading.
Relative metric and line height
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { font-size: 16px; font-size-adjust: 0.5; line-height: 24px; margin: 0; } </style> </head> <body> <p id="a">Sample line with fallback</p> </body></html>The selected relative metric is 0.5 and this one-line box is 24px tall.
Common mistakes
Do not copy percentages from an unrelated font. A metric override in a rule for a missing face can be parsed but never used to render text. Avoid clipping text with rigid heights.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Text processing and international layout. Next lesson: Table layout algorithms.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Font metrics and layout stability — knowledge check
Five questions on font metrics and layout stability.
What can cause shift during a font swap?
Where is size-adjust declared?
Which property can preserve a relative font metric across fonts?
Does a fixed line-height guarantee no shift?
How should overrides be selected?