Key takeaway
- Layout shift and flashes of invisible text explained: how CLS is scored, how FOIT and FOUT differ and how font-display values fix font loading.
A layout shift happens when a visible element on a page changes position or size after it has been drawn, which pushes the content around it, and a flash of invisible text (FOIT) is one cause: the browser hides text while a custom font downloads. Shifts can be intentional, such as a panel that opens after a click, but unexpected ones hurt reading and trust.
This guide is for front end developers and product owners who want stable pages and readable text while fonts load. It covers how layout shift is scored, how FOIT and FOUT differ, what each font-display value does, and a short fix list.
What is layout shift and how is it measured?
When a browser loads a page it gives each element a size and position and arranges the page around them. If one element changes size or moves, the elements next to it move too. The web.dev guide to Cumulative Layout Shift defines Cumulative Layout Shift (CLS) as a measure of the largest burst of layout shift scores for every unexpected layout shift during a page's lifetime. A burst is a group of shifts with less than one second between each, lasting at most five seconds.
| CLS score | Rating |
|---|---|
| 0.1 or less | Good: the level the guide says sites should strive for |
| Between 0.1 and 0.25 | Needs improvement |
| Above 0.25 | Poor |
The guide measures these at the 75th percentile of page loads, split by mobile and desktop. To see how the browser builds a page in the first place, read how the web browser renders pages.
What causes layout shifts?
The same guide lists the common causes:
- Images or videos with unknown dimensions, so the browser cannot reserve space for them.
- Fonts that render larger or smaller than their fallback font, so text reflows when the custom font arrives.
- Third-party ads or widgets that resize themselves dynamically.
For shifts that follow a user action, the guide advises creating space straight away and showing a loading indicator when a network request takes a while. For animations, it recommends transform: scale() instead of changing height and width, and transform: translate() instead of changing top, right, bottom or left. Honour the prefers-reduced-motion setting too.
What are FOIT and FOUT?
The MDN documentation for font-display describes a font display timeline that starts when the browser first tries to use a downloaded font. It has three periods. In the block period, if the font has not loaded, the element must render an invisible fallback font. In the swap period, it renders a visible fallback font and uses the custom font once it loads. In the failure period, the browser treats the font as failed and falls back normally. MDN does not use the terms FOIT and FOUT, but the mapping is straightforward: invisible text during the block period is FOIT, and fallback text that is later replaced is FOUT.
| Question | FOIT (flash of invisible text) | FOUT (flash of unstyled text) |
|---|---|---|
| What the reader sees while the font loads | Blank space where the text will be | Text in a fallback font |
| Main benefit | No visible font change, so the design stays consistent | Content is readable at once |
| Main cost | Content is hidden until the font arrives or the block period ends | Text changes appearance when the custom font is swapped in, which can shift the layout |
| Typical choice when | Brand typography matters more than speed to first text | Reading the content matters more than the exact typeface |
How do the font-display values compare?
MDN lists five values for the font-display descriptor of @font-face. The initial value is auto.
| Value | Block period | Swap period |
|---|---|---|
| auto | Defined by the browser | Defined by the browser |
| block | Short | Infinite |
| swap | Extremely small | Infinite |
| fallback | Extremely small | Short |
| optional | Extremely small | None |
MDN gives no fixed millisecond or second values for "short" and "extremely small". It notes that Firefox exposes the two durations as preferences, so treat any exact figure in older articles, including browser timeouts for font blocking, as out of date and test in the browsers you support. MDN lists the property as Baseline widely available across browsers since January 2020.
How do you fix layout shifts and invisible text?
Work through these steps in order.
- Choose a font-display value. Use
swapif readable text matters most,fallbackfor a short swap window, oroptionalif the browser may skip the custom font on a slow connection. - Reserve space. Give images, video and embeds explicit dimensions, and use
min-heightormin-widthfor content added after load, so nothing below it moves. - Match the fallback. Because fonts that differ in size from their fallback cause shifts, adjust fallback metrics where you can. Our guide to CSS size-adjust for font-face explains one way to do it.
- Load fonts early, but sparingly. Preloading asks the browser to fetch a font sooner, but it competes with other resources, so preload only the fonts above the fold.
- Re-measure. Check CLS again after each change.
@font-face {
font-family: "ExampleFont";
src: url("/fonts/example-font.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
Related techniques help the same goal of faster, steadier pages: the CSS content-visibility property reduces rendering work, code splitting in React loads less code up front, and fluid typography with CSS clamp keeps type scaling smooth. To track the results over time, see performance monitoring tools and management.
How do AI agents change web performance work?
Agents can run page checks on every release, compare CLS before and after a change, flag images without dimensions and open a fix for review. The decision about trading brand typography against speed still belongs to people, so agents need clear rules and an audit trail of what they changed. ElixirClaw is XenonStack's AI agents computing platform for building and running agents like these. For help with the front end itself, see our digital product development and engineering services.
What should you do first?
- Measure CLS on your most visited pages and note which are above 0.1.
- Add
font-displayto every@font-facerule. - Set dimensions on images, video and embeds.
- Reserve space for banners, ads and content that loads late.
- Re-test on a slow connection and on mobile.
To map one page experience decision your agents make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is a layout shift?
A layout shift happens when a visible element changes position or size after it was drawn, which moves the content around it. Cumulative Layout Shift measures the largest burst of unexpected shifts during a page visit.
What is a good CLS score?
The web.dev guide says sites should strive for a CLS of 0.1 or less, measured at the 75th percentile of page loads. Scores above 0.25 are poor.
What is the difference between FOIT and FOUT?
With FOIT the browser hides text until the custom font loads. With FOUT it shows text in a fallback font and swaps in the custom font later.
Which font-display value should I use?
Use swap when readable text matters most, fallback for a short swap window, and optional when the browser may skip the custom font on a slow connection. The initial value is auto, which leaves the choice to the browser.
Do fonts cause layout shift?
Yes. The web.dev guide lists fonts that render larger or smaller than their fallback as a common cause of layout shift.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE