Flash of unstyled content (FOUC)

A flash of unstyled content, or FOUC, is a brief moment during page load when a web page appears with the browser's default styles, as plain black text, blue underlined links and stacked images, before its stylesheet applies and the page snaps into its designed layout. It happens when the browser paints content before the CSS meant for it has arrived or been applied.

The longer version

Reviewers report it without knowing its name. The page "loads broken for a second", the menu "shows as a list of links and then fixes itself", the home page "jumps". By the time anyone takes a screenshot the page looks right, so the report reads as a complaint nobody can reproduce, and it is often closed as such. It is a visual bug with a short life, and it usually appears on a first visit, on a slow connection or in one browser, which is why the developer who loads the page from a warm cache on a fast network never sees it. A page that stays unstyled is a different fault: a stylesheet that failed to load, or a cached page asking for a file a new deployment deleted, which is the territory of cache busting.

By default the browser prevents the flash. MDN's guide to the critical rendering path puts it plainly: "CSS is render blocking: the browser blocks page rendering until it receives and processes all the CSS." A FOUC therefore means that some styling has been taken out of that path. The common causes are a stylesheet loaded asynchronously, for example with the preload and onload pattern web.dev describes for non-critical CSS, without the CSS for the first view inlined; styles injected by JavaScript, as a development build does with Webpack's style-loader or a CSS-in-JS library does in the browser; server-rendered HTML whose styles are only added when the client-side framework hydrates, the cause in Next.js issue 40122 on GitHub, about styled-components, fixed by collecting the styles on the server; custom elements that stay unstyled until their script defines them, which MDN's page on the :defined pseudo-class calls "flashes of ugly unstyled elements"; and third-party widgets that add their own stylesheets late. Web fonts cause two relatives, the flash of unstyled text (FOUT), where fallback text swaps to the web font, and the flash of invisible text (FOIT), where text stays hidden until the font arrives. MDN's font-display reference describes the behaviour behind both, the font's swap and block periods. Wikipedia's article gives flash of unstyled text as another name for FOUC, but the layout in a FOUT is already styled and the fix lies in font loading, so the two are worth keeping apart.

To reproduce it, test a production build, since a development server may inject CSS through JavaScript and flash where the real site does not. In Chrome DevTools, the Network panel's Disable cache checkbox emulates, in Google's words, how a first-time user experiences the site, and the Throttling menu offers fast 4G, slow 4G and 3G presets. Reload with both set, then record the load in the Performance panel with its Screenshots checkbox ticked and click through the frames. Repeat in Safari and Firefox, and after a hard refresh. A useful report names the page, the browser, whether it was a first visit and what the connection was, because each of those changes whether the flash appears.

The fix follows the cause. Keep the CSS needed for the first view in an ordinary stylesheet link in the head, or inline that critical CSS and defer only the rest. Extract styles into files in production builds instead of injecting them from scripts, and collect CSS-in-JS styles during server rendering so the HTML arrives styled. Give undefined custom elements a style that reserves their final size. For fonts, web.dev's font best practices recommend font-display: optional, or swap with the font delivered early enough to avoid a layout shift. Hiding the whole page until it loads removes the flash at a cost: Wikipedia notes an interrupted load can leave a blank page, and a hidden page delays largest contentful paint. A page that jumps from unstyled to styled can also add layout shifts, so the fix shows up in the performance metrics as well as in the review.

Common questions

What causes a flash of unstyled content?

A flash of unstyled content happens when the browser paints a page before the CSS for it has been applied. The usual causes are stylesheets loaded asynchronously, styles injected by JavaScript, server-rendered HTML whose styles arrive only when the framework hydrates, custom elements waiting for their script, and third-party widgets that add stylesheets late.

How do you fix FOUC?

Find the cause first, by reproducing the flash on a production build with the cache disabled and the network throttled. Then keep the CSS for the first view render blocking or inlined, extract injected styles into files, collect CSS-in-JS on the server, and give undefined custom elements a placeholder style. Hiding the page until it loads trades the flash for a blank screen.

What is the difference between FOUC and FOUT?

In a FOUC the whole page appears with the browser's default styles before its stylesheet applies. In a flash of unstyled text, or FOUT, the page is already styled and only the text changes, from a fallback font to the web font. The FOUT is fixed through font loading, with font-display and an early font request, and a FOUC through how the CSS is delivered.

Why does FOUC appear in development and not in production?

Development servers often inject CSS through JavaScript so that styles can update without a reload, which means the page paints before the script runs. Production builds usually extract the CSS into files linked in the head, which the browser waits for. A flash seen only on a development server is normally a property of that server, so check the production build before filing it.

Does FOUC affect Core Web Vitals?

FOUC has no metric of its own. Its causes and its fixes can still move two of the Core Web Vitals. A page that jumps from unstyled to styled can register layout shifts, and a fix that hides the page until everything loads delays largest contentful paint. Measuring both before and after a change shows whether the fix made the load better or only less visible.

How do you report a flash of unstyled content?

Describe what appeared and for how long, for example plain text and a list of links for about a second before the layout appeared. Then name the page, the browser and device, whether it was the first visit or a repeat one, and the connection. A screen recording of a fresh load shows the flash, where a screenshot taken afterwards shows only the finished page.

Bug reports that arrive ready to triage.

Collect replay, console, network and browser context with the Free plan.

<script src="…/widget.js" data-key="pb_pub_…">