Course contentsShow
← Web Development
Lesson 567 of 2,98210. Typography and Design SystemsFree lesson

The font-display Property

Control font loading behavior with font-display values: auto, swap, block, fallback, and optional.

The font-display Property

You'll learn how to control what users see while custom fonts load using the font-display property.

When you use custom web fonts with @font-face, there's a brief moment between when the page loads and when the font file arrives. During this loading period, browsers need to decide: should they show nothing, show fallback text, or do something else? The font-display property gives you control over this behavior.

Understanding Your Options

Think of font-display like instructions for a restaurant host: what should they do when your table isn't ready yet?

auto — The browser decides. Different browsers handle this differently, so it's unpredictable.

swap — Show fallback text immediately, then swap in the custom font when ready. This prevents invisible text (FOIT) but may cause a visible "flash" when fonts switch. Best for readability.

block — Hide text for a short period (~3 seconds), waiting for the custom font. If it doesn't arrive, show fallback. Creates a smooth appearance but risks invisible text.

fallback — A middle ground: brief blocking period (~100ms), then show fallback. The custom font can only swap in during a short window (~3 seconds). After that, stick with fallback until the next page load.

optional — Ultra-brief blocking (~100ms), then the browser decides whether to use the custom font based on connection speed. Prioritizes performance over design consistency.

Using font-display

@font-face {
  font-family: 'MyCustomFont';
  src: url('mycustomfont.woff2') format('woff2');
  font-display: swap;
}

Most developers prefer swap for its balance of performance and readability.

Key Takeaway: The font-display property controls font loading behavior—swap shows text immediately with fallbacks, while block, fallback, and optional offer different trade-offs between visual consistency and performance.