Font metrics override descriptors, f-mods for short. Some new CSS properties for optimizing font loading and reduce CLS due to
font-display: swap. So, the properties added in this draft are:
line-gap-override, which are all percentage values.
If you are like me you are already typing at google "how to get font metrics descriptors" or something like that. So I will help you: I've found this tool searching for "font metrics inspector" which is great and returns far more information than I needed! Yay great!
Except, not great, I don't know how to proceed since no one of this properties are in percentage! As established before, I know your are already typing "How to convert metrics descriptors to percentage", don't fear, I've already figured this one out for you.
To convert the metrics giving by the metrics inspector into values compatible with the new f-mods properties for the FontFace API, you have to take four (4) numbers out of the inspector:
ascender: to use at the
unitsPerEm: which is our reference for 100%
so you can have something like
/* which font to apply to*/
font-family: 'Liberation Sans'
src: local('Liberation Sans');
/* the values we need */
/* applied to the properties */
ascent-override: calc(var(--ascender) / var(--unitsPerEm) * 100%);
descent-override: calc(var(--descender) / var(--unitsPerEm) * 100%);
line-gap-override: calc(var(--lineGap) / var(--unitsPerEm) * 100%);
- Explainer & demos → https://goo.gle/2J0xH4J
- Spec → https://goo.gle/370XDFP
- How to get f-mods for a given font:
- browser compatibility: https://caniuse.com/?search=FontFace API override
- Good explanation: https://simonhearne.com/2021/layout-shifts-webfonts/#reduce-layout-shift-with-f-mods
On a side note, if you are smirking to yourself thinking "aah, cheap SEO tatics literally inserting common search queries in the article body", I'd say you are right, that was the point and I'm not ashamed of doing so :joy:. This is to help people, and if people don't find the text, there is no point in writing, is there? anyway.