CLS measures unexpected movement of visible content. Each shift scores impact fraction × distance fraction. Shifts are grouped into session windows (a window ends after a 1 s gap or at 5 s in total), and CLS is the worst window. Good is ≤ 0.1 at p75. The usual causes are media without dimensions, late-injected content (ads, banners, embeds), web-font swaps and animating layout properties. The fix is to reserve space up front and animate with transform.
hadRecentInput and excluded. Scrolling and hover don't count as input for this purpose.| Cause | Fix |
|---|---|
<img>/<video>/<iframe> without size | Set width and height attributes (browsers derive aspect-ratio from them), or CSS aspect-ratio |
| Ads and embeds that size themselves late | Reserve a min-height slot for the most likely size, and don't collapse the slot when no ad fills it |
| Cookie banners or "app install" bars pushing content down | Overlay them (position: fixed) instead of inserting them into the flow at the top |
| Content loaded after render (recommendations, reviews) | Skeletons with the same dimensions, or insert below the viewport |
| Web font swap changes text metrics | size-adjust, ascent-override etc. on a fallback @font-face to match metrics; preload the font; font-display: optional |
Animating top/height/margin | Animate transform and opacity instead |
| Client-side hydration that swaps the SSR markup | Render the same markup on server and client; avoid if (typeof window) branches in render |
/* Metric-matched fallback reduces the font-swap shift */
@font-face {
font-family: "Brand Fallback";
src: local("Arial");
size-adjust: 104%;
ascent-override: 92%;
}
body { font-family: "Brand", "Brand Fallback", sans-serif; }
new PerformanceObserver(list => {
for (const e of list.getEntries()) {
if (e.hadRecentInput) continue;
for (const s of e.sources ?? []) {
console.log(e.value.toFixed(4), s.node, s.previousRect, s.currentRect);
}
}
}).observe({ type: 'layout-shift', buffered: true });
The layout-shift entry type is Chromium-only, so field CLS data mostly comes from Chrome users. DevTools' Performance panel highlights "Layout shift" clusters, and web-vitals/attribution reports the largest shift target. That's often enough to name the guilty component in your RUM dashboard.
loading="lazy" images with dimensions are fine. Without dimensions they shift when they load as you scroll.web-vitals library handles this; hand-rolled observers often don't.Spotted a mistake or a rights concern? Report an issue