Skip to Content
The Public InterfaceSeptember 12, 2026

The Public Interface

May 1, 2025

How to Prevent Scrollbar Layout Shift

Prevent layout shift caused when removing the scroll from an element with the CSS scrollbar-gutter property.

By Ross Robinocss / layout shift / modal

A common issue when removing the scroll from an element with JavaScript is that is causes the width of the content to change when the scrollbar is hidden. For example, this happens when you are building a modal element that sets the overflow of the body element to hidden when the modal is open.

I came across the scrollbar-gutter property when watching this video from Kevin Powell. It allows you to maintain the width of the scrollbar gutter even when the element isn’t scrollable. It makes for a simple solution to layout shift problem.

Instead of hiding the scrollbar entirely, the thumb becomes hidden and the gutter remains.

Using CSS you can set the property on the :root to stable to apply it to the page, or whichever element you need to target.

Here’s an example of how to remove the page scroll when opening a <dialog> element. With the scrollbar-gutter property set to stable, the page will maintain the same width and no layout shift will occur.…

Continue reading

In brief

A Guide to Creating Popups

How to choose the right approach when developing a web application.

This article outlines various techniques that developers can employ to create accessible popups using HTML, CSS, and JavaScript. I’m going to refer to modals, popovers, and dialogs as popups. Generally, it’s best to avoid popups altogether–they can be obtrustive, especially when they aren’t accessible. Popups can be used when an application needs to alert a message, obtain confirmation, or prompt the user for input. If these cases sound familiar, they are!

June 25, 2023