font-display

CSS font-display Property

The font-display property defines how font files are downloaded and displayed by the browser. This property has the following values:

  • auto

  • block

  • swap

  • fallback

  • optional

The typography was used to be limited to local fonts where the only available fonts were the ones called “web-safe”. Then came @font-face rule allowing to upload font files to a server and write a set of rules naming the font and telling the browser where to download the files. It gave rise to the services which allowed to use custom fonts. But these custom font files can be large and reduce the website load time.

There was another concern connected with FOUT (“flash of unstyled text”). Browsers would display a system font while the custom font was being downloaded. This gave cause for concern as web designers viewed it as the user experience hijacking. Today browsers commonly hide the text until the custom font is downloaded, which is referred to as FOIT (“flash of invisible text”).

But none of the above-mentioned methods is great. Instead, now there is the font-display property telling the browser what we prefer: FOUT or FOIT.

类目类目
Initial Valueauto
Applies toAll elements. It also applies to ::first-letter and ::first-line.
InheritedYes.
AnimatableNo.
VersionCSS1
DOM Syntaxobject.style.fontDisplay = “swap”;

Syntax

Syntax

font-display: auto | block | swap | fallback | optional | initial | inherit;
@font-face {
  font-family: 'MyWebFont';
  /* Define the custom font name */
  src: url('myfont.woff2') format('woff2'), url('myfont.woff') format('woff');
  /* Define where the font can be downlaoded */
  font-display: optional;
}

Values

Values

ValueDescription
autoFont display is defined by the browser.
blockBriefly hides the text until the font has fully downloaded.
swapGives the font face a very small block period and an infinite swap period.
fallbackGives the font face a very small block period and a short swap period.
optionalGives the font face a very small block period and no swap period.
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部