{"id":253584,"date":"2017-04-17T05:02:14","date_gmt":"2017-04-17T12:02:14","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=253584"},"modified":"2020-03-25T06:30:42","modified_gmt":"2020-03-25T13:30:42","slug":"font-display","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/f\/font-display\/","title":{"rendered":"font-display"},"content":{"rendered":"\n
The The Here’s another way to think about them<\/p>\n\n\n\nfont-display<\/code> property defines how font files are loaded and displayed by the browser. It is applied to the
@font-face<\/code><\/a> rule which defines custom fonts in a stylesheet.<\/p>\n\n\n\n
@font-face {\n font-family: 'MyWebFont'; \/* Define the custom font name *\/\n src: url('myfont.woff2') format('woff2'),\n url('myfont.woff') format('woff'); \/* Define where the font can be downloaded *\/\n font-display: fallback; \/* Define how the browser behaves during download *\/\n}<\/code><\/pre>\n\n\n\n\n\n\n
Values<\/h3>\n\n\n
font-display<\/code> property accepts five values:<\/p>\n\n\n\n
auto<\/code> (default): Allows the browser to use its default method for loading, which is most often similar to the
block<\/code> value.<\/li>
block<\/code>: Instructs the browser to briefly hide the text until the font has fully downloaded. More accurately, the browser draws the text with an invisible placeholder then swaps it with the custom font face as soon as it loads. This is also known as a “flash of invisible text” or FOIT.<\/li>
swap<\/code>: Instructs the browser to use the fallback font to display the text until the custom font has fully downloaded. This is also known as a “flash of unstyled text” or FOUT.<\/li>
fallback<\/code>: Acts as a compromise between the
auto<\/code> and
swap<\/code> values. The browser will hide the text for about 100ms and, if the font has not yet been downloaded, will use the fallback text. It will swap to the new font after it is downloaded, but only during a short swap period (probably 3 seconds).<\/li>
optional<\/code>: Like
fallback<\/code>, this value tells the browser to initially hide the text, then transition to a fallback font until the custom font is available to use. However, this value also allows the browser to determine whether the custom font is even used at all, using the user’s connection speed as a determining factor where slower connections are less likely to receive the custom font.<\/li><\/ul>\n\n\n\n