CSS scrollbar-gutter Property
The CSS scrollbar-gutter property controls whether space is reserved for a scrollbar, helping prevent layout shifts when scrollbars appear or disappear.
It is particularly useful for scrollable containers whose content changes dynamically. The property can reserve space along the scrollbar edge or on both inline edges of a container. Its effect depends on whether the browser uses traditional or overlay scrollbars.
scrollbar-gutter Syntax
The scrollbar-gutter property accepts auto, stable, or stable both-edges.
Basic Syntax
selector {
scrollbar-gutter: stable;
}
Available Values
.container {
scrollbar-gutter: auto;
}
.container {
scrollbar-gutter: stable;
}
.container {
scrollbar-gutter: stable both-edges;
}
CSS-Wide Keywords
.container {
scrollbar-gutter: initial;
}
.container {
scrollbar-gutter: inherit;
}
.container {
scrollbar-gutter: unset;
}
.container {
scrollbar-gutter: revert;
}
.container {
scrollbar-gutter: revert-layer;
}
The both-edges keyword cannot be used alone. It must accompany stable.
Property Values
| Value | Description |
|---|---|
auto |
Uses the browser's default scrollbar gutter behavior. This is the initial value. |
stable |
Reserves space for traditional scrollbars in eligible scroll containers, even when a scrollbar is not currently needed. |
stable both-edges |
Reserves matching space on both inline edges when a scrollbar gutter would otherwise be present on one edge. |
initial |
Resets the property to auto. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to auto because it is not inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Scrolling boxes |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Related properties | overflow, scrollbar-width |
| Specification | CSS Overflow Module Level 3 |
Valid Values
.container {
scrollbar-gutter: auto;
}
.container {
scrollbar-gutter: stable;
}
.container {
scrollbar-gutter: stable both-edges;
}
.container {
scrollbar-gutter: initial;
}
.container {
scrollbar-gutter: inherit;
}
Invalid Values
.container {
scrollbar-gutter: both-edges;
}
.container {
scrollbar-gutter: always;
}
.container {
scrollbar-gutter: 20px;
}
.container {
scrollbar-gutter: stable auto;
}
.container {
scrollbar-gutter: stable, both-edges;
}
The property does not accept custom gutter dimensions, comma-separated values, or the keyword always.
How It Works
A scrollbar gutter is the space between the inner border edge and the outer padding edge of a scrolling box where a traditional scrollbar can appear.
Without a stable gutter, the space available for content may change when a traditional scrollbar appears or disappears.
Step 1: Create a Scroll Container
.scroll-panel {
height: 250px;
overflow-y: auto;
}
The browser displays a scrollbar when the content exceeds the panel's available height.
Step 2: Reserve Scrollbar Space
.scroll-panel {
scrollbar-gutter: stable;
}
On systems with traditional scrollbars, space is reserved even when the content does not overflow.
Step 3: Add or Remove Content
When the content changes, the reserved gutter helps keep the content width consistent.
Default Behavior
.scroll-panel {
scrollbar-gutter: auto;
}
The browser reserves gutter space according to its normal scrollbar behavior.
No Fixed Gutter Size
The gutter's dimensions depend on the browser and operating system. The property does not accept a pixel width.
Important Consideration
The property reserves space only where applicable. It does not create scrolling or force scrollbars to appear.
The auto Value
The auto value uses the browser's default scrollbar gutter behavior.
Example
.scroll-panel {
overflow-y: auto;
scrollbar-gutter: auto;
}
Traditional Scrollbars
With overflow: auto, a traditional scrollbar generally occupies space only when content overflows and a scrollbar is needed.
Overlay Scrollbars
Overlay scrollbars do not consume a separate gutter. They appear over the content when the browser or operating system chooses to display them.
Possible Layout Changes
If a traditional scrollbar appears after content is added, the available content width can decrease.
When to Use auto
Use auto when default scrollbar behavior is acceptable and reserving additional space is unnecessary.
Important Consideration
The auto value does not guarantee a consistent content width when traditional scrollbars appear or disappear.
The stable Value
The stable value reserves space for traditional scrollbars when the scrolling box uses overflow: auto, scroll, or hidden, even if no scrollbar is currently displayed.
Basic Example
.scroll-panel {
height: 250px;
overflow-y: auto;
scrollbar-gutter: stable;
}
Without Overflowing Content
When content fits inside the container, a traditional scrollbar may not be visible, but the gutter remains reserved.
With Overflowing Content
When content exceeds the available space, the scrollbar uses the previously reserved gutter.
Dynamic Content
.dynamic-panel {
max-height: 300px;
overflow-y: auto;
scrollbar-gutter: stable;
}
This is useful for panels that gain or lose content after loading or user interaction.
No Effect With Overlay Scrollbars
When the browser uses overlay scrollbars, stable does not reserve a traditional scrollbar gutter.
Important Consideration
Use stable to reduce layout shifts caused by changing scrollbar visibility, not to guarantee an identical layout across operating systems.
The both-edges Value
The stable both-edges value reserves matching gutter space on both inline edges when a scrollbar gutter is present on one edge.
Basic Example
.scroll-panel {
overflow-y: auto;
scrollbar-gutter: stable both-edges;
}
Balanced Inline Edges
On systems with traditional scrollbars, the property can create matching space on the opposite side of the scrollbar gutter.
Centered Content
.centered-panel {
width: 400px;
overflow-y: auto;
scrollbar-gutter: stable both-edges;
text-align: center;
}
Matching gutters can help centered content remain visually balanced.
Comparing stable and stable both-edges
| Value | Behavior |
|---|---|
stable |
Reserves the scrollbar gutter where the traditional scrollbar belongs. |
stable both-edges |
Also reserves matching space on the opposite inline edge. |
No Gutter With Overlay Scrollbars
The both-edges keyword does not force gutters to appear when the browser uses overlay scrollbars.
Important Consideration
The extra gutter reduces the space available for content. Use it when visual balance is more important than maximizing the content area.
Traditional and Overlay Scrollbars
The behavior of scrollbar-gutter depends on how the browser and operating system display scrollbars.
Traditional Scrollbars
Traditional scrollbars occupy space within the scrolling box. Their presence can reduce the space available for content.
Overlay Scrollbars
Overlay scrollbars are drawn over the content rather than occupying a separate gutter. They may remain hidden until scrolling occurs.
Behavior Comparison
| Value | Traditional Scrollbars | Overlay Scrollbars |
|---|---|---|
auto |
Gutter appears when needed according to overflow behavior. | No gutter is reserved. |
stable |
Reserves gutter space for eligible scrolling boxes. | No gutter is reserved. |
stable both-edges |
Reserves matching inline-edge gutters when applicable. | No gutter is reserved. |
Platform Differences
Some operating systems use traditional scrollbars by default, while others use overlay scrollbars or allow users to choose between them.
Important Consideration
Do not assume that a reserved gutter will be visible on every device. Test with both traditional and overlay scrollbar settings when possible.
Interaction With overflow
The overflow property determines how overflowing content is handled. It also affects whether a scrollbar gutter can be reserved.
| Overflow Value | Behavior With stable |
|---|---|
auto |
Reserves a traditional scrollbar gutter even when content does not overflow. |
scroll |
Reserves space for a traditional scrollbar. |
hidden |
Reserves gutter space even though the scrollbar itself is hidden. |
visible |
Does not reserve a scrollbar gutter. |
clip |
Does not reserve a scrollbar gutter. |
overflow: auto
.panel {
overflow-y: auto;
scrollbar-gutter: stable;
}
This is a common combination for dynamically changing content.
overflow: scroll
.panel {
overflow-y: scroll;
scrollbar-gutter: stable;
}
The container is configured for scrolling, and a traditional scrollbar gutter is reserved.
overflow: hidden
.panel {
overflow: hidden;
scrollbar-gutter: stable;
}
Space can still be reserved for a traditional scrollbar even though the scrollbar is not displayed.
overflow: visible
.panel {
overflow: visible;
scrollbar-gutter: stable;
}
No scrollbar gutter is reserved because the element is not configured as a scrolling box.
overflow: clip
.panel {
overflow: clip;
scrollbar-gutter: stable;
}
The clip value does not establish a scroll container or reserve a scrollbar gutter.
Important Consideration
When overflow-x and overflow-y use different values, CSS overflow computation rules can affect the resulting scrolling behavior.
Layout and Sizing
Reserved scrollbar gutters occupy space inside the scrolling box, affecting the area available for content.
Content Width
.panel {
width: 400px;
overflow-y: auto;
scrollbar-gutter: stable;
}
On systems with traditional scrollbars, part of the panel's interior is reserved for the scrollbar gutter.
Box Sizing
.panel {
box-sizing: border-box;
width: 400px;
padding: 20px;
overflow-y: auto;
scrollbar-gutter: stable;
}
The gutter reduces the available interior space without changing the declared border-box width.
Flexbox Layouts
.flex-panel {
display: flex;
flex-direction: column;
height: 300px;
overflow-y: auto;
scrollbar-gutter: stable;
}
Stable gutters can help prevent content width changes when flex containers gain or lose overflowing content.
Grid Layouts
.grid-panel {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 15px;
height: 300px;
overflow-y: auto;
scrollbar-gutter: stable;
}
The grid tracks are laid out within the available content area after any reserved gutter space is accounted for.
Viewport Scrollbar
html {
scrollbar-gutter: stable;
}
When applied to the document's root element, the value is propagated to the viewport. This can help prevent horizontal layout shifts when a traditional viewport scrollbar appears.
Important Consideration
Gutter dimensions are controlled by the browser. The property does not provide a way to specify an exact amount of reserved space.
Writing Modes and Direction
The both-edges keyword uses logical inline edges rather than fixed physical left and right sides.
Left-to-Right Layout
.panel {
direction: ltr;
overflow-y: auto;
scrollbar-gutter: stable both-edges;
}
In a typical horizontal writing mode, matching gutter space can be reserved on both sides of the content.
Right-to-Left Layout
.panel {
direction: rtl;
overflow-y: auto;
scrollbar-gutter: stable both-edges;
}
The matching gutters follow the inline edges even when the scrollbar is positioned differently.
Vertical Writing Modes
.panel {
writing-mode: vertical-rl;
overflow: auto;
scrollbar-gutter: stable both-edges;
}
In vertical writing modes, inline edges correspond to the top and bottom rather than the left and right.
Logical vs. Physical Edges
| Writing Mode | Inline Edges |
|---|---|
horizontal-tb |
Left and right |
vertical-rl |
Top and bottom |
vertical-lr |
Top and bottom |
Important Consideration
Use stable both-edges when symmetrical gutter space is useful across different writing directions and modes.
Practical Examples
Dynamic Content Panel
.dynamic-panel {
height: 300px;
overflow-y: auto;
scrollbar-gutter: stable;
}
Reserves space when content is added or removed.
Centered Content Panel
.centered-panel {
height: 300px;
overflow-y: auto;
scrollbar-gutter: stable both-edges;
text-align: center;
}
Creates matching inline-edge gutters when traditional scrollbar space is reserved.
Page Layout Stability
html {
scrollbar-gutter: stable;
}
Helps reduce layout shifts when the viewport scrollbar appears or disappears.
Scrollable Sidebar
.sidebar {
max-height: 80vh;
overflow-y: auto;
scrollbar-gutter: stable;
}
Useful when sidebar navigation changes length.
Scrollable Modal Content
.modal-content {
max-height: 70vh;
overflow-y: auto;
scrollbar-gutter: stable;
}
Helps keep modal content aligned when the amount of text changes.
Data Table Container
.table-wrapper {
max-height: 350px;
overflow: auto;
scrollbar-gutter: stable;
}
Reserves scrollbar space in a container displaying variable amounts of table data.
Resetting the Gutter
.scroll-panel {
scrollbar-gutter: auto;
}
Restores the browser's default gutter behavior.
scrollbar-gutter Example
This interactive example compares auto, stable, and stable both-edges. Use the buttons to add or remove content and observe how the available content space changes.
HTML Example
<div class="gutter-demo">
<div class="gutter-controls">
<button type="button" class="add-content">Add Content</button>
<button type="button" class="remove-content">Remove Content</button>
</div>
<div class="gutter-grid">
<div class="gutter-panel auto">
<h3>auto</h3>
<div class="items">
<p>Sample content</p>
</div>
</div>
<div class="gutter-panel stable">
<h3>stable</h3>
<div class="items">
<p>Sample content</p>
</div>
</div>
<div class="gutter-panel both">
<h3>stable both-edges</h3>
<div class="items">
<p>Sample content</p>
</div>
</div>
</div>
</div>
CSS Example
.gutter-demo .gutter-controls {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 15px;
}
.gutter-demo .gutter-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 15px;
}
.gutter-demo .gutter-panel {
height: 180px;
overflow-y: auto;
border: 1px solid #94a3b8;
background-color: #f8fafc;
}
.gutter-demo .gutter-panel h3 {
margin: 0;
padding: 10px;
font-size: 1rem;
text-align: center;
background-color: #dbeafe;
}
.gutter-demo .gutter-panel .items {
padding: 10px;
}
.gutter-demo .gutter-panel .items p {
margin: 0 0 10px;
padding: 10px;
background-color: #e2e8f0;
text-align: center;
}
.gutter-demo .auto {
scrollbar-gutter: auto;
}
.gutter-demo .stable {
scrollbar-gutter: stable;
}
.gutter-demo .both {
scrollbar-gutter: stable both-edges;
}
JavaScript Example
const demo = document.querySelector(".gutter-demo");
const panels = demo.querySelectorAll(".items");
let itemCount = 1;
demo.querySelector(".add-content").addEventListener("click", () => {
itemCount++;
panels.forEach((panel) => {
const item = document.createElement("p");
item.textContent = "Sample content " + itemCount;
panel.appendChild(item);
});
});
demo.querySelector(".remove-content").addEventListener("click", () => {
if (itemCount <= 1) return;
panels.forEach((panel) => {
panel.lastElementChild.remove();
});
itemCount--;
});
auto
Sample content
stable
Sample content
stable both-edges
Sample content
Click Add Content several times until the panels overflow. On systems with traditional scrollbars, the auto panel may change its content width when a scrollbar appears, while the stable panels reserve space in advance.
Comparing the Results
| Panel | Expected Behavior |
|---|---|
auto |
Scrollbar gutter appears only when needed. |
stable |
Scrollbar gutter remains reserved when applicable. |
stable both-edges |
Matching inline-edge gutters remain reserved when applicable. |
Overlay Scrollbar Note
On systems using overlay scrollbars, the panels may appear nearly identical because overlay scrollbars do not reserve gutter space.
Changing the Gutter Value
.gutter-demo .stable {
scrollbar-gutter: stable both-edges;
}
The panel requests matching gutters on both inline edges instead of only the scrollbar edge.
Restoring Default Behavior
.gutter-demo .stable {
scrollbar-gutter: auto;
}
The panel returns to the browser's default scrollbar gutter behavior.
Accessibility Considerations
Stable scrollbar gutters can improve layout consistency, but they should not interfere with native scrolling or user preferences.
Prevent Unexpected Layout Changes
Reserving gutter space can reduce horizontal shifts when content changes and traditional scrollbars appear.
Preserve Scrollbar Visibility
The property does not hide scrollbars. Avoid removing visible scrolling controls without a clear alternative.
Maintain Keyboard Scrolling
Scrollable regions should remain accessible to keyboard users, including users who navigate without a mouse.
Respect System Preferences
Do not attempt to force traditional scrollbars when the user prefers overlay scrollbars.
Avoid Unnecessary Content Compression
The stable both-edges value can reduce the available content width. Test narrow layouts to ensure text and controls remain usable.
Responsive Layout Testing
Verify that reserved gutters do not cause unwanted wrapping, clipping, or horizontal overflow at smaller viewport widths.
Keep Content Reachable
Do not combine restrictive heights and overflow settings in ways that prevent users from reaching important content.
Common Mistakes
Using both-edges Alone
.container {
scrollbar-gutter: both-edges;
}
The both-edges keyword must be combined with stable.
Specifying a Pixel Width
.container {
scrollbar-gutter: 20px;
}
The property does not accept custom gutter dimensions.
Using the always Keyword
.container {
scrollbar-gutter: always;
}
The always keyword is not a valid value.
Expecting a Visible Scrollbar
Reserving gutter space does not force a scrollbar to appear.
Ignoring Overlay Scrollbars
Overlay scrollbars do not reserve gutter space, even when stable is specified.
Using overflow: visible
.container {
overflow: visible;
scrollbar-gutter: stable;
}
This combination does not establish a scrollbar gutter.
Confusing scrollbar-gutter With scrollbar-width
scrollbar-gutter controls reserved space, while scrollbar-width controls scrollbar thickness preferences.
Confusing scrollbar-gutter With scrollbar-color
scrollbar-gutter does not change scrollbar colors.
Assuming Inheritance
The property is not inherited. Apply it to each scrolling box that needs a stable gutter.
Expecting Identical Gutter Dimensions
Scrollbar gutter sizes depend on the browser and operating system.
Overlooking Reduced Content Space
Reserved gutters reduce the area available for content, especially when using stable both-edges.
Important Considerations
Keep the following points in mind when using scrollbar-gutter:
- It controls whether space is reserved for scrollbars.
- The initial value is
auto. - The property is not inherited.
- The
stablevalue reserves traditional scrollbar gutter space when applicable. - The
stable both-edgesvalue can reserve matching space on both inline edges. - The
both-edgeskeyword cannot be used alone. - The property does not accept custom gutter dimensions.
- Traditional scrollbars occupy gutter space.
- Overlay scrollbars do not reserve a separate gutter.
- The property does not force scrollbars to appear.
- The property does not create a scroll container.
- Its behavior depends on the computed overflow values.
- The
visibleandclipoverflow values do not reserve gutters. - Reserved gutters reduce the space available for content.
- Gutter dimensions depend on the browser and operating system.
- Applying the property to the root element can stabilize viewport scrollbar space.
- The property can help reduce layout shifts caused by dynamic content.
- It works with Flexbox and Grid scroll containers.
- Logical inline edges adapt to writing modes and text direction.
- Test layouts with both traditional and overlay scrollbars.
- Use
scrollbar-widthandscrollbar-colorfor other aspects of scrollbar styling.
Browser Support
The CSS scrollbar-gutter property is widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.
Although browser support is broad, the visible result depends on whether the browser and operating system use traditional or overlay scrollbars.
For current compatibility information, visit Can I Use? and search for scrollbar-gutter.
Feature Detection
@supports (scrollbar-gutter: stable) {
.scroll-panel {
scrollbar-gutter: stable;
}
}
Feature queries can apply stable gutter behavior only when the browser recognizes the property.
Fallback Behavior
When unsupported, the browser uses its default scrollbar gutter behavior. Content remains scrollable according to its overflow settings.
Platform Differences
Testing on multiple operating systems is useful because scrollbar rendering and visibility preferences can affect the results.
Specifications
The scrollbar-gutter property is defined in the CSS Overflow Module Level 3 specification.
The specification defines scrollbar gutter reservation, including the auto, stable, and both-edges behaviors.
For additional documentation and examples, consult MDN Web Docs.
