CSS3 Intermediate Modern Layout · 6 min read

CSS scrollbar-gutter

Lesson 36 of 41 in the CSS3 learning path.

How do I stop a list from shifting when a scrollbar appears?

scrollbar-gutter: stable keeps space for a scrollbar even before the content overflows.

A catalog that grows by one row should not shove the heading sideways when the bar appears.

Syntax & Parameters

Syntax
.list { overflow: auto; scrollbar-gutter: stable; }

Example

Interactive preview available
list.css
.list {
  max-height: 12rem;
  overflow: auto;
  scrollbar-gutter: stable;
  padding-right: .25rem;
}
.list li {
  padding: .4rem 0;
}
html {
  scrollbar-gutter: stable;
}
.list li + li {
  border-top: 1px solid #e2e8f0;
}

Expected Output

The list keeps a blank strip where the scrollbar will sit. Adding items does not shift the text.

Line-by-Line Walkthrough

  1. The list has a max height.
  2. overflow auto scrolls only when needed.
  3. stable reserves the gutter immediately.
  4. The header beside the list does not jump.
  5. html can reserve the page gutter too.
  6. Rows keep a light divider.
  7. both-edges is the value when you also scroll backward.
  8. Classic overlay scrollbars may ignore the gutter. Test the browsers you ship.

Common Pitfalls & Security

Read the limits before you copy this.

  • stable wastes a little width on short lists. That is the point.
  • overlay scrollbars on some systems do not consume the gutter.
  • Setting it on every nested box stacks empty strips.
  • It does not style the scrollbar color. That is scrollbar-color.

Best Practices & Modern Standards

Reserve the gutter on the scrolling list, not on every card.

Pair it with overflow: auto and a max height.

Real-World Use

The lesson index in a sidebar grows during search. The titles stay aligned when the scrollbar appears.

Frequently Asked Questions

What does stable mean?

Always reserve the space, even when nothing overflows yet.

What is stable both-edges?

Reserve space on both sides, useful for bidirectional overflow.

Does this color the bar?

No. Use scrollbar-color for that.

Will every browser honor it?

Current engines do. Overlay bars may still draw on top of the content.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…