scrollbar-gutter
The scrollbar-gutter
CSS property allows authors to reserve space for the scrollbar, preventing unwanted layout changes as the content grows while also avoiding unnecessary visuals when scrolling isn't needed.
An element's scrollbar gutter is the space between the inner border edge and the outer padding edge, where the browser may display a scrollbar. If no scrollbar is present, the gutter will be painted as an extension of the padding.
The browser determines whether classic scrollbars or overlay scrollbars are used:
- Classic scrollbars are always placed in a gutter, consuming space when present.
- Overlay scrollbars are placed over the content, not in a gutter, and are usually partially transparent.
Syntax
/* Initial value */ scrollbar-gutter: auto; /* "stable" keyword, with optional modifier */ scrollbar-gutter: stable; scrollbar-gutter: stable both-edges; /* Global values */ scrollbar-gutter: inherit; scrollbar-gutter: initial; scrollbar-gutter: revert; scrollbar-gutter: unset;
Values
auto
-
The initial value. Classic scrollbars create a gutter when
overflow
isscroll
, or whenoverflow
isauto
and the box is overflowing. Overlay scrollbars do not consume space. stable
-
When using classic scrollbars, the gutter will be present if
overflow
isauto
,scroll
, orhidden
even if the box is not overflowing. When using overlay scrollbars, the gutter will not be present. both-edges
-
If a gutter would be present on one of the inline start/end edges of the box, another will be present on the opposite edge as well.
Formal definition
Initial value | auto |
---|---|
Applies to | scrolling boxes |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
Formal syntax
auto | stable && both-edges?
Examples
Example 1
Prevent unneeded layout changes as the content growing or shrinking causes the scrollbar to appear/disappear:
.container { scrollbar-gutter: stable; }
Example 3
Add symmetric spacing to both sides of the box so the content is centered:
.container { scrollbar-gutter: stable both-edges; }
Example 4
Align the contents of a non-scrolling element and a scrolling one adjacent to it:
.header { overflow: hidden; scrollbar-gutter: stable; } .container { scrollbar-gutter: stable; }
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
scrollbar-gutter |
94
88-94
|
94 |
No |
No |
80 |
No |
94 |
94
88-94
|
No |
No |
No |
No |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-gutter