--- url: "https://web.dev/articles/debug-layout-shifts" titulek: "Debug layout shifts | Articles | web.dev" h1: "Debug layout shifts Stay organized with collections Save and categorize content based on your preferences." popis: "Learn how to identify and fix layout shifts." jazyk: "en" kanonicka: "https://web.dev/articles/debug-layout-shifts" drobecky: ["Articles", "Debug layout shifts"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 22:28:05" znaku: 14209 slov: 2137 kodovani: "iso-8859-2" sha256: "dcfb4e407480dba20c8ad9f97816909e3b072da3bd132529b1aa6e86c37bf082" --- Debug layout shifts Stay organized with collections Save and categorize content based on your preferences. Learn how to identify and fix layout shifts. Katie Hempenius Barry Pollard Published: Mar 11, 2021, Last updated: Feb 7, 2025 The first part of this article discusses tooling for debugging layout shifts, while the second part discusses the thought process to use when identifying the cause of a layout shift. Tooling You can debug Layout Shifts using the Layout Instability API, or with tooling like DevTools that summarizes data from this API in a more easily digestible format. Layout Instability API The [Layout Instability API](https://wicg.github.io/layout-instability/) is the browser mechanism for measuring and reporting layout shifts. All tools for debugging layout shifts, including DevTools, are ultimately built upon the Layout Instability API. However, using the Layout Instability API directly is a powerful debugging tool due to its flexibility. Usage The same code [snippet](/articles/cls#measure_cls_in_javascript) that measures [Cumulative Layout Shift (CLS)](/articles/cls) can also serve to debug layout shifts. The following snippet logs information about layout shifts to the console. Inspecting this log will provide you information about when, where, and how a layout shift occurred. `let cls = 0; new PerformanceObserver((entryList) => { for (const entry of entryList.getEntries()) { if (!entry.hadRecentInput) { cls += entry.value; console.log('Current CLS value:', cls, entry); } } }).observe({type: 'layout-shift', buffered: true});` When running this script be aware that: The `buffered: true` option indicates that the [`PerformanceObserver`](https://developer.mozilla.org/docs/Web/API/PerformanceObserver) should check the browser's [performance entry buffer](https://www.w3.org/TR/performance-timeline-2/#dfn-performance-entry-buffer) for performance entries that were created before the observer's initialization. As a result, the `PerformanceObserver` will report layout shifts that happened both before and after it was initialized. Keep this in mind when inspecting the console logs. An initial glut of layout shifts can reflect a reporting backlog, rather than the sudden occurrence of numerous layout shifts. To avoid impacting performance, the `PerformanceObserver` waits until the main thread is idle to report on layout shifts. As a result, depending on how busy the main thread is, there may be a slight delay between when a layout shift occurs and when it is logged in the console. This script ignores layout shifts that occurred within 500 ms of user input and therefore don't count towards CLS. Information about layout shifts is reported using a combination of two APIs: the [`LayoutShift`](https://wicg.github.io/layout-instability/#layoutshift) and [`LayoutShiftAttribution`](https://wicg.github.io/layout-instability/#sec-layout-shift-attribution) interfaces. Each of these interfaces are explained in more detail in the following sections. LayoutShift Each layout shift is reported using the `LayoutShift` interface. The contents of an entry look like this: `duration: 0 entryType: "layout-shift" hadRecentInput: false lastInputTime: 0 name: "" sources: (3) [LayoutShiftAttribution, LayoutShiftAttribution, LayoutShiftAttribution] startTime: 11317.934999999125 value: 0.17508567530168798` The previous entry indicates a layout shift during which three DOM elements changed position. The layout shift score of this particular layout shift was `0.175`. These are the properties of a `LayoutShift` instance that are most relevant to debugging layout shifts: Property Description `sources` The `sources` property lists the DOM elements that moved during the layout shift. This array can contain up to five sources. In the event that there are more than five elements impacted by the layout shift, the five largest (as measured by impact on layout stability) sources of layout shift are reported. This information is reported using the LayoutShiftAttribution interface (explained in more detail below). `value` The `value` property reports the [layout shift score](/articles/cls#layout_shift_score) for a particular layout shift. `hadRecentInput` The `hadRecentInput` property indicates whether a layout shift occurred within 500 milliseconds of user input. `startTime` The `startTime` property indicates when a layout shift occurred. `startTime` is indicated in milliseconds and is measured relative to the [time that the page load was initiated](https://www.w3.org/TR/hr-time-2/#sec-time-origin). `duration` The `duration` property will always be set to `0`. This property is inherited from the [`PerformanceEntry`](https://developer.mozilla.org/docs/Web/API/PerformanceEntry) interface (the `LayoutShift` interface extends the `PerformanceEntry` interface). However, the concept of duration does not apply to layout shift events, so it is set to `0`. For information on the `PerformanceEntry` interface, refer to the [spec](https://w3c.github.io/performance-timeline/#the-performanceentry-interface). LayoutShiftAttribution The `LayoutShiftAttribution` interface describes a single shift of a single DOM element. If multiple elements shift during a layout shift, the `sources` property contains multiple entries. For example, the following JSON corresponds to a layout shift with one source: the downward shift of the `