Back to the journal

The loading spinner is hiding a layout that jumps three times before it settles

Open your own product on a mid-range Android phone over a throttled connection and watch the first two seconds carefully. The header appears, then drops a few pixels when a banner loads. A button you were about to tap slides down because an image above it finally arrived. A font swap nudges a paragraph and reflows everything below it. None of these feels like a bug, and none of them shows up in a desktop demo on fast fibre. But together they are the thing Google measures as Cumulative Layout Shift, and more importantly they are the thing a user feels as a page that will not sit still long enough to be used. This week is about hunting those shifts down, because they are almost always cheap to fix once you can see them.

Why the page jumps after it looks done

Layout shift happens when an element that already has a position on screen gets pushed somewhere else by content that loads later. The classic cause is an image or embed with no declared dimensions. The browser lays out the page assuming the image takes zero height, paints everything below it, and then reflows the moment the image headers arrive and it learns the real size. Everything underneath leaps down. The user has already started reading, or worse, started reaching for a control, and the target moves.

The sneakier causes are the ones that feel like good engineering. A font loaded with the default swap behaviour renders fallback text first, then re-renders in your brand font, and the slightly different metrics shift every line. An ad or cookie banner injected at the top of the body pushes the whole document down. A component that fetches data and renders a skeleton of one height, then swaps to real content of a different height. An accordion or 'read more' that expands on load because of a hydration mismatch. Each is a small, defensible decision, and the sum is a page that visibly rearranges itself twice after it appeared ready.

The reason this is easy to miss is that your development machine lies to you. Fonts are cached, images are warm, the network is instant, and React or your framework of choice has already hydrated before you look. CLS is a slow-network, cold-cache, real-device phenomenon. If you only ever test the happy fast path, you will ship a page that is calm for you and jittery for everyone on a train or a cheap handset.

Reserve the space before the content arrives

The core fix for images is boring and effective: give every image an explicit width and height attribute, or a CSS aspect-ratio, so the browser can reserve the correct box before a single byte of the image loads. Modern browsers use the width and height attributes to compute an aspect ratio even when CSS makes the image responsive, so you keep your fluid layout and lose the jump. For background images and hero banners set a fixed min-height or aspect-ratio on the container. The principle generalises: anything that arrives late should have its space reserved from the first paint.

Apply the same thinking to data-driven components. If a card list renders a skeleton, make the skeleton the same height as a real card, not a thin grey bar that doubles in size when content lands. If a section can be empty or full, decide whether it holds its height in both states or collapses, and be deliberate about it rather than letting the fetch decide. For embeds like maps, videos or third-party widgets, wrap them in a container with a known aspect ratio so the reflow happens inside a reserved box instead of shoving the footer around.

Fonts deserve their own attention. Preload the one or two font files that appear above the fold so the swap happens early rather than mid-scroll. Choose a fallback font whose metrics are close to your brand font, and tune it with the size-adjust and the ascent and descent override descriptors on a local font face so the fallback occupies roughly the same space. The line still re-renders, but it no longer reflows, which is the part that scores against you and annoys the reader.

Measure it where it actually hurts

You cannot fix what you only feel occasionally, so make the measurement repeatable. In Chrome DevTools, open the Performance panel, enable CPU and network throttling to a mid-tier phone profile, disable the cache, and record a reload. The layout shift markers appear on the timeline and clicking one tells you exactly which element moved and by how much. This takes two minutes and will usually surface the three culprits on your most important page before you have finished your coffee.

For a number you can track over time, use the web-vitals library to log the CLS value from real sessions, or read field data in Search Console if your site has enough traffic. The gap between your lab score and your field score is itself the insight: a good lab score and a poor field score means real users are hitting conditions you never test, usually slow fonts, late third-party scripts or heavy pages on weak devices. Pay attention to shifts that happen after user interaction too, because a jump that lands just as someone taps is the one that gets them to the wrong destination.

A common mistake is chasing a single aggregate number instead of the individual shifts behind it. CLS is a sum, and one big offender often dominates. Find the element with the largest single shift score and fix that first; you will frequently halve the total with one container that gets a reserved height. Another trap is treating the cookie or consent banner as untouchable third-party territory. If it injects at the top of the body and shoves everything down, either overlay it as a fixed element that does not affect flow, or reserve its height. It is your page, even when the script is not yours.

The takeaway

On Monday, open your highest-traffic page in DevTools with network and CPU throttling on and the cache disabled, record a cold reload, and write down the three biggest layout shifts and the elements that caused them. Add explicit width and height or aspect-ratio to every image and embed on that page so their boxes are reserved from first paint. Make any loading skeleton match the height of the content it stands in for, and decide deliberately whether empty states hold or collapse their space. Preload your above-the-fold font and tune a metrics-matched fallback so the swap stops reflowing lines. Move any banner or consent prompt out of document flow or reserve its height. Then wire up the web-vitals library to report CLS from real sessions, so the next regression shows up as a number instead of a complaint, and you keep the page still for the people who are actually trying to use it.

tags-placeholder

FROM IDEAS TO SOMETHING REAL

Your next chapter.
Let’s build it.

A website, an app, a better way to work. Tell us what you have in mind.

Start a conversation