CSS font-display Explained
Understand the CSS font-display property, its available values, font loading behavior, fallback fonts and best practices for fast and accessible websites.
The CSS font-display property controls how a web browser handles a custom font while it is loading. It determines whether text is immediately displayed using a fallback font, temporarily hidden, or replaced by the web font when it becomes available. Choosing the right font-display value can improve perceived performance, reduce invisible text and help create a more stable reading experience.
Web fonts are loaded separately from the HTML and CSS needed to render a page. This means a browser may need to display text before the requested font has finished downloading. The font-display property gives developers control over this behavior and is an important part of modern font-loading optimization.
What Is font-display?
font-display is a descriptor used inside an @font-face rule. It tells the browser how to render text while the associated font resource is unavailable and what to do if the font takes too long to load.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: swap;
}The descriptor does not select a font or define the visual properties of the typeface. Instead, it controls the loading and rendering behavior of that particular web font.
Why font-display Matters
Without an intentional font-loading strategy, users can experience invisible text, delayed text rendering or visible changes when a custom font replaces a fallback font. These behaviors can make a page feel slower and may affect layout stability and readability.
- Controls when text becomes visible.
- Determines whether a fallback font is used during loading.
- Helps reduce invisible text.
- Influences perceived page performance.
- Can affect layout changes when fonts are swapped.
- Provides predictable behavior for web font loading.
The font-display Values
CSS provides five commonly used font-display values: auto, block, swap, fallback and optional. Each value represents a different strategy for handling the period before a web font becomes available.
| Value | General Behavior | Typical Use |
|---|---|---|
| auto | Browser chooses the font loading behavior | Default behavior |
| block | Text may remain invisible briefly while the font loads | When the custom font is important |
| swap | Fallback font is displayed immediately, then replaced | Most content-focused websites |
| fallback | Short wait followed by fallback, with limited swapping | Balanced loading behavior |
| optional | Font may be skipped if it is not available quickly | Performance-focused optional fonts |
font-display: auto
The auto value leaves font-loading behavior up to the browser. It is the default when no font-display value is specified. Because the exact behavior is controlled by the user agent, auto provides less explicit control than the other values.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: auto;
}For applications where font loading behavior is important to performance or visual consistency, explicitly choosing a strategy such as swap or optional is usually more predictable.
font-display: block
The block value prioritizes the custom font. During the initial font-loading period, the browser may render little or no visible text using the custom face. If the font does not arrive quickly, the browser can fall back to another font and may later swap to the requested font when it becomes available.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: block;
}This approach can be appropriate when displaying the intended typeface is more important than showing text immediately. However, hiding text during font loading can make the page appear slower and is generally less desirable for large amounts of body content.
font-display: swap
The swap value tells the browser to display text using an available fallback font while the web font downloads. Once the custom font becomes available, the browser replaces the fallback with the requested font.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: swap;
}swap is one of the most common choices for content-oriented websites because it prioritizes immediate text visibility. Users can begin reading while the custom font loads in the background.
font-display: fallback
The fallback value provides a compromise between block and swap. The browser allows a short period for the custom font to load. If the font is not available quickly enough, the fallback font is used. The custom font may still replace the fallback if it becomes available within the browser's allowed period.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: fallback;
}fallback can be useful when the custom typeface is desirable but not essential to understanding the content. It limits the amount of time users wait for the font while still allowing the intended font to be used when loading is fast enough.
font-display: optional
The optional value gives the browser the greatest freedom to prioritize performance. If the font is not available quickly enough, the browser may decide not to use the web font for the current page view. The fallback font can remain in use instead.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: optional;
}optional is useful when a custom font provides visual enhancement rather than essential functionality. It allows users with slow connections or constrained conditions to avoid waiting for a non-essential font.
swap vs fallback vs optional
The most important practical difference between these values is how aggressively the browser prioritizes the custom font after the initial rendering period. swap strongly favors eventually using the web font, fallback provides a shorter opportunity for the font to load, and optional allows the browser to prioritize performance over loading the custom font.
| Value | Text First? | Custom Font Priority | Performance Focus |
|---|---|---|---|
| block | Not immediately | High | Lower |
| swap | Yes | High | Good |
| fallback | Yes after a short wait | Medium | Good |
| optional | Yes | Low | Very high |
Using font-display with @font-face
font-display belongs inside the @font-face rule that defines the web font. It should be configured together with the font family, source file and appropriate format.
@font-face {
font-family: "Inter Custom";
src: url("/fonts/inter-custom.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
body {
font-family: "Inter Custom", Arial, sans-serif;
}The fallback stack remains important even when font-display is configured. The browser needs an alternative font for situations where the web font has not loaded, fails to load or is intentionally not used.
Choosing a Good Fallback Font
A fallback font should be reasonably similar to the web font in size, character width and overall appearance. A poor match can cause significant text reflow when the custom font becomes available.
- Choose a similar font category.
- Compare character widths.
- Consider x-height and overall proportions.
- Check line wrapping at common viewport sizes.
- Use a sensible system font as a final fallback.
body {
font-family: "Inter Custom", Arial, sans-serif;
}font-display and Layout Shifts
Changing from a fallback font to a web font can alter text width and line height. As a result, paragraphs may wrap differently, headings can change size and nearby elements may move. This can contribute to visible layout instability.
font-display itself does not eliminate these changes. It controls font-loading behavior, while the choice of fallback font and font metrics influences how large the visual difference becomes.
font-display and Performance
Web fonts are additional resources that must be downloaded, decoded and made available before the browser can use them. font-display can improve perceived performance by allowing text to appear without waiting indefinitely for the custom font.
However, font-display is only one part of font optimization. Font file size, font formats, caching, the number of font families and weights, preload decisions and server performance can all affect how quickly a font becomes available.
Use WOFF2 for Modern Web Fonts
WOFF2 is generally the preferred web font format for modern browsers because it provides efficient compression and is designed for web delivery. Smaller font files reduce the amount of data that needs to be downloaded before the custom typeface becomes available.
@font-face {
font-family: "Example Font";
src: url("/fonts/example.woff2") format("woff2");
font-display: swap;
}Avoid Loading Unnecessary Font Weights
Every font weight or style that is requested can add another resource to the page. Loading ten font variations when a design only uses three increases transfer size and can make font loading less efficient.
| Font Resource | Recommendation |
|---|---|
| Regular | Load if used for body text |
| Medium | Load only if required |
| Bold | Load if used by headings or emphasis |
| Italic | Load only when required |
| Unused weights | Do not load |
When to Use swap
swap is a strong general-purpose choice when readable text should appear immediately and the custom font should eventually be used. It is particularly suitable for body text, documentation, articles and other content where waiting for typography would interfere with reading.
- Articles and documentation.
- Blogs and content websites.
- Marketing pages with substantial text.
- Applications where immediate text visibility is important.
- Sites where the custom font is important but not required for functionality.
When to Use optional
optional is useful when the custom font is primarily decorative or when maximum loading performance is more important than guaranteeing that the custom font appears. The browser can continue using a fallback font rather than delaying the experience for a non-essential resource.
When to Use fallback
fallback is useful when you want to give a custom font a limited opportunity to load but do not want to keep swapping fonts indefinitely. It can be a practical middle ground for designs where typography matters but immediate rendering remains important.
When to Use block
block can be appropriate when displaying the correct custom typeface is especially important and a short period of invisible text is acceptable. This might apply to certain highly branded interfaces, although it should be used carefully for primary content.
Preloading Fonts
For critical fonts that are needed very early during page rendering, preload can help the browser discover the font resource sooner. However, preloading every font can waste bandwidth and compete with other critical resources.
<link
rel="preload"
href="/fonts/example.woff2"
as="font"
type="font/woff2"
crossorigin
/>Preload should generally be reserved for fonts that are genuinely important to the initial rendering experience. A font that is only used below the fold or on a specific page does not necessarily need to be preloaded globally.
Common font-display Mistakes
Font-loading problems often come from treating font-display as a complete performance solution. The property controls rendering behavior, but it cannot compensate for unnecessarily large font files, excessive font variations or poorly selected fallback fonts.
- Using block for all fonts without considering text visibility.
- Using swap with a dramatically different fallback font.
- Loading many unused font weights.
- Preloading every font on the website.
- Ignoring font file size.
- Forgetting to define a fallback font stack.
- Treating font-display as a replacement for broader font optimization.
Best Practices
- Choose font-display intentionally for each web font.
- Prefer swap when immediate text visibility is important.
- Consider optional for non-essential decorative fonts.
- Use fallback when a limited font-loading window is appropriate.
- Use block only when temporary invisible text is acceptable.
- Serve modern compressed font formats such as WOFF2.
- Load only the font weights and styles that are actually needed.
- Choose fallback fonts with similar metrics.
- Preload only genuinely critical fonts.
- Test font loading on slow connections and mobile devices.
Testing Font Loading
Font behavior should be tested under different network conditions rather than only on a fast development connection. A font that appears instantly during local development may take much longer to load for users on slower networks.
- Test with throttled network connections.
- Test on mobile devices.
- Check the page before the font finishes loading.
- Observe whether text remains visible.
- Look for layout changes after the font swaps.
- Verify that fallback typography remains readable.
font-display and Accessibility
Typography is part of the reading experience, so font loading should not prevent users from accessing important content. A readable fallback font and a sensible font-display strategy help ensure that text remains available even when the custom font is slow or unavailable.
Developers should also consider font size, line height, contrast, spacing and responsive behavior. A technically optimized font-loading strategy is not enough if the resulting typography is difficult to read.
Frequently Asked Questions
What does font-display do?
font-display controls how a browser renders text while a web font is loading and what happens when the font becomes available. It is used inside an @font-face rule.
What is the most common font-display value?
swap is one of the most common choices because it allows text to appear immediately using a fallback font and then replaces it with the custom font when available.
What is the difference between swap and optional?
swap strongly favors using the custom font after it loads, while optional gives the browser more freedom to prioritize performance and may leave the fallback font in use.
Does font-display prevent layout shifts?
No. font-display controls font-loading behavior but does not guarantee stable layout. Choosing a fallback font with similar metrics can reduce visible changes when the web font is applied.
Should I use font-display: swap?
swap is a good general-purpose option when text should remain visible immediately and the custom font should eventually be used. The best value still depends on the role of the font and the site's performance goals.
Can font-display improve website performance?
It can improve perceived performance by preventing unnecessary delays in displaying text. However, font file size, the number of fonts, caching, preload decisions and server performance also affect font-loading performance.
Helpful Typography Tools
A CSS Font Face Generator helps create @font-face declarations with font sources, weights and font-display settings, a Font Stack Generator helps build practical fallback stacks, a Typography Scale Generator helps create consistent heading and text sizes, a CSS Formatter improves the readability of font-related CSS, and a CSS Variable Generator can help centralize reusable typography values.
Conclusion
The CSS font-display property gives developers direct control over how web fonts behave while they are loading. The main choices are block, swap, fallback and optional, with each providing a different balance between immediate text visibility, custom font usage and performance. For many content-focused websites, swap provides a practical default because users can start reading immediately while the custom font loads. Regardless of the chosen value, good fallback fonts, efficient WOFF2 files, limited font variations and careful resource loading are essential for a fast, readable and stable typography experience.