A product page can load quickly and still feel unreliable. A shopper reaches for “Add to cart,” an image finishes loading, and the button moves. The page is technically responsive, but the interface has changed underneath the user.
Cumulative Layout Shift, or CLS, measures this kind of visual instability. Reducing it is less about making every asset load faster and more about making the page account for content before that content arrives.
What CLS measures
A layout shift occurs when a visible element moves from one rendered position to another between frames. The browser scores each unexpected shift using two factors: the portion of the viewport affected and the distance the affected elements move.
For example, if elements covering half the viewport move by 10% of the viewport height, the shift score is approximately 0.5 × 0.1, or 0.05. The actual calculation accounts for the affected areas and movement in both dimensions.
CLS is not simply the sum of every shift during a visit. It uses the largest session window: a group of shifts separated by less than one second, spanning no more than five seconds in total. This keeps a long visit from accumulating an unlimited score.
For Core Web Vitals, a CLS of 0.1 or less is considered good. The target is assessed at the 75th percentile of visits, separately for mobile and desktop. A good average can therefore hide a problem affecting a substantial group of users.
Shifts that occur within 500 milliseconds of qualifying user input are generally excluded. That does not make every post-click movement acceptable: a slow response can fall outside that window, and scroll or hover interactions do not receive the same exclusion.
Start with the shifts users actually experience
A page may look stable in a quick local test but shift on slower devices, after scrolling, or when a third-party service responds late. Field data tells us whether the problem occurs in real visits; lab tools help us reproduce and explain it.
Use the Chrome User Experience Report, PageSpeed Insights, or a real-user monitoring system to identify affected page types and device classes. Then reproduce representative pages in Chrome DevTools:
- Record a page load in the Performance panel, using a realistic viewport and network conditions.
- Inspect layout shift entries and their highlighted regions.
- Test beyond the initial load: scroll, open menus, load more results, and wait for delayed content.
- Repeat with different conditions, such as a returning visitor, a blocked third-party request, or a slow font response.
The highlighted element is often the victim, not the cause. If a heading moves down, the cause might be an image, banner, or ad slot inserted above it. Look for the first element whose dimensions changed, rather than immediately editing the element that moved.
Lab and field measurements can also differ for legitimate reasons. A lab run may stop before a late shift occurs, while field data can reflect shifts throughout the page’s lifetime. CrUX can include shifts inside iframes that a page’s own JavaScript cannot directly observe.
Give images and embeds a place to land
Images without known dimensions are a common source of load-time shifts. The browser initially lays out the page with little or no space for the image, then moves surrounding content when its dimensions become available.
For an image with a known intrinsic size, include width and height attributes:
<img
src="/images/linen-chair-800.jpg"
srcset="
/images/linen-chair-400.jpg 400w,
/images/linen-chair-800.jpg 800w,
/images/linen-chair-1200.jpg 1200w
"
sizes="(max-width: 600px) 100vw, 50vw"
width="1200"
height="900"
alt="Linen armchair in a reading corner"
>
img {
max-width: 100%;
height: auto;
}
The attributes let the browser infer an aspect ratio before the image loads. Responsive CSS can still scale it to the available width. The candidates in this srcset should share the same aspect ratio; otherwise, switching candidates can change the space required.
For video embeds or media whose dimensions are controlled by a container, reserve the shape in CSS:
.video-frame {
aspect-ratio: 16 / 9;
width: 100%;
}
.video-frame iframe {
display: block;
width: 100%;
height: 100%;
border: 0;
}
Art-directed images need extra care. If a mobile crop is portrait and a desktop crop is landscape, one fixed ratio will not describe both layouts. Set the appropriate ratio at each breakpoint, or provide dimensions for the relevant sources where supported and test the result.
Lazy loading does not remove the need for dimensions. In fact, an undimensioned lazy-loaded image may cause a shift later, just as the user reaches it.
Treat dynamic content as part of the layout
Ads, recommendations, consent notices, and promotional banners often arrive after the initial HTML. Their timing is variable, but their potential effect on the page is predictable: if they enter normal document flow without reserved space, content below them moves.
Ads and third-party widgets
Reserve a slot based on the sizes the placement can actually serve:
.ad-slot {
min-height: 250px;
}
@media (max-width: 600px) {
.ad-slot {
min-height: 100px;
}
}
The right reservation depends on the ad configuration. If a slot can render several heights, reserving the largest one avoids expansion but may leave visible whitespace. Reserving a smaller height saves space but accepts some shift when a larger creative appears. We can reduce that trade-off by restricting the allowed sizes for a placement.
Empty responses need a plan too. Collapsing an unfilled slot after the page is visible can shift everything below it. If an empty slot must disappear, doing so before it is visible is safer than collapsing it in front of the reader. Third-party content inside an iframe can also resize its container, so the iframe’s outer dimensions matter even when we cannot control its contents.
Skeletons, loading states, and inserted UI
A skeleton is useful only when it approximates the final layout. A short loading bar that becomes a tall product card merely postpones the shift. Match the expected image ratio, card padding, and typical text height as closely as the design permits.
For content with unpredictable height, consider where it enters the page. A notification placed above an article pushes the article down. A notification presented as an overlay can avoid moving the document, although it must not obscure essential controls or create accessibility problems.
User-triggered content deserves the same care. An accordion opening in response to a click may be excluded from CLS when it responds promptly, but an unexpectedly large or delayed expansion can still make the interface difficult to use.
Make font loading less disruptive
Web fonts can change line breaks, heading heights, and button widths when they replace a fallback font. A small difference in character widths can add a line to a heading and push an entire section downward.
Start by choosing a fallback with similar proportions. Then consider metric overrides to make the fallback occupy space closer to the final font:
@font-face {
font-family: "Brand Sans";
src: url("/fonts/brand-sans.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: "Brand Sans Fallback";
src: local("Arial");
size-adjust: 98%;
ascent-override: 90%;
descent-override: 22%;
line-gap-override: 0%;
}
body {
font-family: "Brand Sans", "Brand Sans Fallback", sans-serif;
}
These values are illustrative, not universal. Measure them against the actual font and fallback, then check headings, navigation labels, and text-heavy pages at several viewport widths.
font-display: swap makes text visible quickly, but it can produce a visible font swap. optional may avoid a late swap on some visits, at the cost of not always showing the custom font. Preloading a critical font can help it arrive sooner, but preload only fonts needed immediately and ensure the preload matches the eventual font request.
Animate without moving the document around
Animations that change layout properties such as height, margin, top, or left can move surrounding elements. For visual movement that should not reflow the page, prefer transform and opacity:
.toast {
opacity: 0;
transform: translateY(0.5rem);
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible {
opacity: 1;
transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
.toast {
transition: none;
}
}
Transforms change the element’s visual position without changing the space it occupies in normal flow. They are not a substitute for sound layout: a transformed element can still overlap text or controls. Use them when the surrounding content should remain stationary.
Capture enough field data to find recurring causes
Real-user monitoring becomes more useful when it can distinguish a high CLS score on a search results page from the same score on a checkout page. The web-vitals attribution build can report the largest shift associated with a CLS measurement:
import { onCLS } from "web-vitals/attribution";
// Use a normalized page type supplied by the application, not a raw URL.
const pageType = document.documentElement.dataset.pageType || "unknown";
onCLS((metric) => {
const payload = {
id: metric.id,
name: metric.name,
value: metric.value,
pageType,
largestShiftTime: metric.attribution.largestShiftTime,
largestShiftValue: metric.attribution.largestShiftValue
};
navigator.sendBeacon(
"/rum",
new Blob([JSON.stringify(payload)], { type: "application/json" })
);
});
The server should group measurements by page type and device class, then examine the 75th percentile rather than relying on individual reports. Keep the metric ID so repeated reports for the same measurement can be handled as updates, not added together. If collecting element selectors or URLs for diagnosis, review them for sensitive data first.
For single-page applications, CLS is ordinarily measured over the document lifecycle, not automatically reset for each client-side route. A route recorded when the callback runs may therefore be different from the route where a shift happened. If route-level diagnosis matters, record route transitions separately and correlate them with shift timing.
A useful fix is one that survives both views of the problem: the suspicious movement disappears in a reproducible trace, and the affected page group’s field distribution improves as real visits accumulate.