Authoring Modern CSS Fonts Level 4 @font-face Rules Without Layout Shift
Combining font-display: swap, unicode-range, and Metric Descriptors
Hand-written @font-face snippets copied from ten-year-old tutorials still clutter stylesheets with obsolete .eot, .svg, and .ttf URLs while omitting metric overrides. When font-display: swap renders fallback text immediately and swaps in your custom WOFF2 150 milliseconds later, mismatched x-heights, advance widths, and ascender heights trigger Cumulative Layout Shift (CLS) reflows down the entire document.
CSS Fonts Module Level 4 solves swap reflow natively by letting you declare a companion local() @font-face rule equipped with size-adjust, ascent-override, descent-override, and line-gap-override. Remember that browser engines multiply override percentages by the already size-adjusted em box—so dividing normalized ascender and descender em values by (sizeAdjust / 100) locks vertical line height with sub-pixel accuracy.
- Outputs clean single-source format("woff2") declarations with exact font-weight and style.
- Derives unicode-range automatically from actual mapped cmap entries in the output binary.
- Computes size-adjusted ascent-override, descent-override, and line-gap-override percentages.
- Exports both the .woff2 font and a downloadable .css stylesheet locally.