Skip to main content
XenonStack

Data Visualization

XenonStack Blog Layout Shift and FOIT: How to Fix Font Loading

| Published | Updated

Layout Shift and FOIT: How to Fix Font Loading
7:47

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.

Two-column diagram comparing FOIT and FOUT. FOIT: block period, blank space, consistent design, content delayed. FOUT: swap period, readable text, font swap, possible reflow.
CLS scoreRating
0.1 or lessGood: the level the guide says sites should strive for
Between 0.1 and 0.25Needs improvement
Above 0.25Poor

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.

QuestionFOIT (flash of invisible text)FOUT (flash of unstyled text)
What the reader sees while the font loadsBlank space where the text will beText in a fallback font
Main benefitNo visible font change, so the design stays consistentContent is readable at once
Main costContent is hidden until the font arrives or the block period endsText changes appearance when the custom font is swapped in, which can shift the layout
Typical choice whenBrand typography matters more than speed to first textReading 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.

ValueBlock periodSwap period
autoDefined by the browserDefined by the browser
blockShortInfinite
swapExtremely smallInfinite
fallbackExtremely smallShort
optionalExtremely smallNone

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.

  1. Choose a font-display value. Use swap if readable text matters most, fallback for a short swap window, or optional if the browser may skip the custom font on a slow connection.
  2. Reserve space. Give images, video and embeds explicit dimensions, and use min-height or min-width for content added after load, so nothing below it moves.
  3. 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.
  4. 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.
  5. 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?

  1. Measure CLS on your most visited pages and note which are above 0.1.
  2. Add font-display to every @font-face rule.
  3. Set dimensions on images, video and embeds.
  4. Reserve space for banners, ads and content that loads late.
  5. 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.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue