CSS3’s New Font-Display Property is here!
These days, we take web fonts way for granted. We didn’t always have the option of having almost any typeface at our fingertips for our text. Technically, we could, but then we would be stuck knowing that our fancy fonts would only be visible on a handful of desktops, with most defaulting to basic backup fonts like Verdana. Web fonts changed everything. They brought some much needed variety to the scene, a few abuses of typography, and some bloated page weight because them fonts themselves were loaded, and flashes of unstyled or invisible text.
It’s a bit of a usability problem, though, when text is invisible until the custom font gets loaded. If users are stuck looking at a blank page for too long
(and too long might be milliseconds) they might just decide to leave. And that’s fair enough. It’s not user-friendly.
Fast forward a few years, and we’re making progress on controlling the way fonts load. Until now, we’ve done it with third-party libraries and APIs.
But now, at last, this functionality is coming to CSS.
Enter the font-display property. It’s currently only in Opera, Opera for Android, and Chrome. (It was first introduced in Chrome 49 as an experimental feature.)
It comes with four options: auto, swap, fallback, and optional.
Basically, choosing font-display: auto will leave the browser to act as it does now. Text will be invisible until the custom font loads.
swap is probably what most people will use. If the font isn’t loaded, the next available font defined in the font-family property will be used.
When the web font loads, it will be replaced. This is basically a flash of unstyled content, but that’s more user-friendly than invisible content, I think.
fallback splits the difference between those first two options. For a delay of 100 milliseconds, the text will be invisible. If the custom font is loaded by then, it will be used.
If not, the next font in the line of succession will rule until the custom font is loaded.
optional works like fallback, except the browser may decide not to load the custom font at all, if the user’s connection is too slow.
And there we have it. Mind you, the display-font is meant to be used in a @font-face declaration. That means it won’t work with third-party font providers like Typekit or Google Fonts for now. Once font-display becomes more widespread,
however, it’s likely that they’ll implement some sort of option for this feature.