Core Web Vitals CLS Counts Scrollbar Shifts
When JavaScript adds articles or cards after the page has loaded and the page becomes long enough to show a scrollbar, centered content shifts to the left by half the scrollbar's width. In the Chromium I tested, this sideways shift was recorded as a layout-shift and counted toward CLS (Cumulative Layout Shift) in Core Web Vitals. This applies to pages where the scrollbar appears or disappears without any user action, such as a page that loads a list after it opens, or a page that turns off background scrolling when a modal (dialog) opens automatically.
A shift right after the user pressed a button was excluded. On a page with scrollbar-gutter: stable set on html, the shift did not happen at all.
The test environment was Ubuntu 24.04, Node.js 22, and web-vitals 5.3.0. The browser was Chromium 158 (headless) bundled with Playwright 1.63.0, and the viewport was 800px wide and 600px high. Playwright launches Chromium with --hide-scrollbars, so I removed this argument and let a scrollbar that takes up space (15px in this environment) appear before measuring.
I did not test Firefox, Safari, the regular (non-test) Chrome, Windows, macOS, or smartphones. I also did not test environments with overlay scrollbars that are drawn on top of content, Lighthouse, or real user data such as PageSpeed Insights field data or Search Console.
- 1. The test page
- 2. A sideways shift from a scrollbar appearing gave CLS 0.0142
- 3. The shift also counted when the scrollbar disappeared
- 4. A scrollbar that appeared right after a button press was excluded
- 5. Preventing the sideways shift with scrollbar-gutter: stable
- 6. Playwright's default settings cannot measure this shift
The test page
The page centers the header and body inside a container (.container) with a maximum width of 560px. The body has two 120px-high cards, and a "Show more" button is fixed at the bottom right with position: fixed. At first the page fits in the viewport, so no scrollbar appears.
.container { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.card { height: 120px; margin: 16px 0; background: #ddd; }
One second after the page opens, JavaScript adds 10 cards. The new cards go below the existing ones, so the elements already on screen do not move vertically. The only movement is the horizontal shift caused by the scrollbar appearing.
// Add cards 1000ms after load (they go below the existing cards and make the page longer)
const addCards = (n) => {
for (let i = 0; i < n; i++) {
const d = document.createElement('div');
d.className = 'card';
main.append(d);
}
};
setTimeout(() => addCards(10), 1000);
The test page can switch conditions with URL parameters. The code above has been trimmed to only the part for this condition.
On the page, I used PerformanceObserver to receive layout-shift entries. I recorded the time, value, and hadRecentInput of each shift, along with the before and after positions (sources) of each shifted element. I also registered onCLS from web-vitals with reportAllChanges: true. Times in the output are milliseconds since the page was opened.
A sideways shift from a scrollbar appearing gave CLS 0.0142
When the cards were added, the page width (document.documentElement.clientWidth) narrowed from 800px to 785px. The left edge of the container moved from 104px to 96.5px, a shift of 7.5px to the left.

This shift was recorded as a layout-shift with hadRecentInput=false, and onCLS reported a CLS of 0.0142.
== grow-center (カード2枚のページで、1000ms 後にカードを10枚足す(中央寄せ), ?at=1000&n=10)
start clientWidth=800 logoLeft=104 cards=2
onCLS report at=37 value=0.0000 entries=[]
changed t=1032 cards=12 clientWidth=785 logoLeft=96.5
shift t=1032 value=0.0142 hadRecentInput=false sources=3
source main prev(x=104,y=80,w=592) cur(x=96.5,y=80,w=592)
source logo prev(x=104,y=0,w=592) cur(x=96.5,y=0,w=592)
source more prev(x=692.1,y=552,w=83.9) cur(x=677.1,y=552,w=83.9)
onCLS report at=1035 value=0.0142 entries=[1032]
(logo is the header container, main is the body container, and more is the button at the bottom right.)
Three elements shifted. The two containers moved 7.5px, and the fixed button at the bottom right moved 15px, the same as the scrollbar's width. On a page without the button, the same shift gave a CLS of 0.0071.
== grow-center-nobtn (同じ操作(中央寄せ、右下の固定ボタンなし), ?at=1000&n=10&nobtn)
…
shift t=1023 value=0.0071 hadRecentInput=false sources=2
source main prev(x=104,y=80,w=592) cur(x=96.5,y=80,w=592)
source logo prev(x=104,y=0,w=592) cur(x=96.5,y=0,w=592)
onCLS report at=1024 value=0.0071 entries=[1023]
(I omitted the start and changed lines and the first onCLS report line.)
According to web.dev's explanation of CLS, the shift value is computed from the largest distance any element moved in a frame, divided by the larger of the viewport's width or height. With the button present, the largest movement went from 7.5px to 15px. The value roughly doubled, from 0.0071 to 0.0142.
On a page with the container left-aligned, the container did not move. The only element that moved when the cards were added was the fixed button at the bottom right, and the value was 0.0001.
== grow-left (同じ操作(左寄せ), ?at=1000&n=10&layout=left)
start clientWidth=800 logoLeft=0 cards=2
onCLS report at=42 value=0.0000 entries=[]
changed t=1022 cards=12 clientWidth=785 logoLeft=0
shift t=1023 value=0.0001 hadRecentInput=false sources=1
source more prev(x=692.1,y=552,w=83.9) cur(x=677.1,y=552,w=83.9)
onCLS report at=1024 value=0.0001 entries=[1023]
All of these values are at or below 0.1, which web.dev gives as the target for good CLS. However, even on a page with no other shifts, CLS went above 0 just because the scrollbar appeared.
The shift also counted when the scrollbar disappeared
Shifts in the opposite direction were also counted. On a page with 12 cards, I removed 10 cards one second after load. The scrollbar disappeared, the container moved right from 96.5px to 104px, and the CLS was 0.0137.
== shrink-center (カード12枚のページで、1000ms 後にカードを10枚減らす(中央寄せ), ?start=12&at=1000&n=-10)
start clientWidth=785 logoLeft=96.5 cards=12
onCLS report at=49 value=0.0000 entries=[]
changed t=1026 cards=2 clientWidth=800 logoLeft=104
shift t=1027 value=0.0137 hadRecentInput=false sources=3
source main prev(x=96.5,y=80,w=592) cur(x=104,y=80,w=592)
source logo prev(x=96.5,y=0,w=592) cur(x=104,y=0,w=592)
source more prev(x=677.1,y=552,w=83.9) cur(x=692.1,y=552,w=83.9)
onCLS report at=1027 value=0.0137 entries=[1027]
The same thing happened when I added overflow: hidden to html to stop background scrolling while a modal is open. On a page with 12 cards, adding overflow: hidden one second after load removed the scrollbar, and the same value of 0.0137 was counted.
== lock-center (カード12枚のページで、1000ms 後に html に overflow: hidden を付ける(中央寄せ), ?start=12&at=1000&lock)
start clientWidth=785 logoLeft=96.5 cards=12
onCLS report at=48 value=0.0000 entries=[]
changed t=1021 cards=12 clientWidth=800 logoLeft=104
shift t=1021 value=0.0137 hadRecentInput=false sources=3
source main prev(x=96.5,y=80,w=592) cur(x=104,y=80,w=592)
source logo prev(x=96.5,y=0,w=592) cur(x=104,y=0,w=592)
source more prev(x=677.1,y=552,w=83.9) cur(x=692.1,y=552,w=83.9)
onCLS report at=1022 value=0.0137 entries=[1021]
A scrollbar that appeared right after a button press was excluded
When I changed the trigger for adding cards from a timer to a click on the "Show more" button, the same 0.0142 shift had hadRecentInput=true. lastInputTime was 2ms before the shift, and onCLS did not report a new value after its first 0.
== grow-click (「もっと見る」を押してカードを10枚足す(中央寄せ), ?at=click&n=10)
start clientWidth=800 logoLeft=104 cards=2
onCLS report at=35 value=0.0000 entries=[]
changed t=1084 cards=12 clientWidth=785 logoLeft=96.5
shift t=1077 value=0.0142 hadRecentInput=true lastInputTime=1075 sources=3
source main prev(x=104,y=80,w=592) cur(x=96.5,y=80,w=592)
source logo prev(x=104,y=0,w=592) cur(x=96.5,y=0,w=592)
source more prev(x=692.1,y=552,w=83.9) cur(x=677.1,y=552,w=83.9)
web.dev's explanation of CLS says that shifts within 500ms of user input are marked with hadRecentInput and can be excluded from the calculation. In the draft specification for the Layout Instability API, input means actions such as mousedown, keydown, and pointerdown, along with events that directly change the size of the viewport. In the timer-based measurement, the scrollbar appeared and the width narrowed to 785px, but hadRecentInput stayed false, so the shift was not excluded.
Scrollbar shifts were counted only when the scrollbar appeared or disappeared without any click or other action, such as when cards were added or removed by a timer, or when overflow: hidden was applied.
Preventing the sideways shift with scrollbar-gutter: stable
Setting scrollbar-gutter: stable on html keeps the space for the scrollbar even when no scrollbar is showing. The left edge of the container was 96.5px from the start. Adding cards or applying overflow: hidden did not move the container, and no layout-shift entries were recorded.
html { scrollbar-gutter: stable; }
== grow-gutter (同じ操作(中央寄せ、html に scrollbar-gutter: stable), ?at=1000&n=10&css=gutter)
start clientWidth=800 logoLeft=96.5 cards=2
onCLS report at=34 value=0.0000 entries=[]
changed t=1025 cards=12 clientWidth=785 logoLeft=96.5
== lock-gutter (同じ操作(中央寄せ、html に scrollbar-gutter: stable), ?start=12&at=1000&lock&css=gutter)
start clientWidth=785 logoLeft=96.5 cards=12
onCLS report at=36 value=0.0000 entries=[]
changed t=1022 cards=12 clientWidth=800 logoLeft=96.5
(The second block is a page with 12 cards where overflow: hidden was applied to html.)
According to MDN's description of scrollbar-gutter, stable reserves space for the scrollbar when overflow is auto, scroll, or hidden in an environment with scrollbars that take up space, even if the content does not overflow. Because the space stays reserved when overflow: hidden stops scrolling, the shift when a modal opens was also prevented.
Setting overflow-y: scroll on html so the scrollbar is always shown also prevented the shift when cards were added. However, even on the short page with two cards, the page width was narrowed from the start (to 785px) by the scrollbar's width.
Playwright's default settings cannot measure this shift
When Chromium is launched with Playwright's defaults, --hide-scrollbars is added and the scrollbar takes up no space. In this state, adding cards or applying overflow: hidden left the page width at 800px, and no layout-shift was recorded.
== grow-center (カード2枚のページで、1000ms 後にカードを10枚足す(中央寄せ), ?at=1000&n=10)
start clientWidth=800 logoLeft=104 cards=2
onCLS report at=42 value=0.0000 entries=[]
changed t=1029 cards=12 clientWidth=800 logoLeft=104
If you want a Playwright test to measure CLS and also catch sideways shifts from scrollbars, launch the browser with ignoreDefaultArgs to remove --hide-scrollbars. Without this change, the shift will not be recorded.
const browser = await chromium.launch({ ignoreDefaultArgs: ['--hide-scrollbars'] });





