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 modifiers */ scrollbar-gutter: stable; scrollbar-gutter: stable both; scrollbar-gutter: stable force; scrollbar-gutter: stable both force; /* "always" keyword, with optional modifiers */ scrollbar-gutter: always; scrollbar-gutter: always both; scrollbar-gutter: always force; scrollbar-gutter: always both force;
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
isscroll
orauto
even if the box is not overflowing. When using overlay scrollbars, the gutter will not be present. always
- The scrollbar gutter will always be present when
overflow
isscroll
orauto
, regardless of the type of scrollbar or of whether the box is overflowing. both
- 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.
force
- The keywords
stable
andalways
will also be in effect whenoverflow
isvisible
,hidden
orclip
. Only the gutter will be displayed, not a scrollbar.
Formal definition
Initial value | auto
|
Applies to | all elements |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
Formal syntax
auto | [ stable | always ] && both? && force?
Examples
Example 1
Prevent layout changes when the content grows or shrinks:
.container {
scrollbar-gutter: stable;
}
Example 2
Prevent an overlay scrollbar from obscuring content:
.container {
scrollbar-gutter: always;
}
Example 3
Keep the symmetry between both sides of the box:
.container {
scrollbar-gutter: stable both;
}
Example 4
Reserve the same amount of space on the edges of an element that is adjacent to a scrolling element as is being reserved in the latter, so that both line up visually:
.header {
scrollbar-gutter: always force;
}
.container {
scrollbar-gutter: always;
}
Specifications
Specification | Status | Comment |
---|---|---|
CSS Overflow Module Level 4The definition of 'scrollbar-gutter' in that specification. | Unknown | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
No compatibility data found. Please contribute data for "css.properties.scrollbar-gutter" (depth: 1) to the MDN compatibility data repository.
See also
scrollbar-gutter by Mozilla Contributors is licensed under CC-BY-SA 2.5.