Vanta Logo
SPONSOR
Automate SOC 2 & ISO 27001 compliance with Vanta. Get $1,000 off.
Up to date
Published
3 min read

Trevor I. Lasn

Staff Software Engineer, Engineering Manager

scrollbar-width & scrollbar-gutter: CSS Properties for Layout Control

Prevent content shifts and refine scrollable UIs with scrollbar-width and scrollbar-gutter

The scrollbar-width CSS property tackles a common challenge in web design - balancing the need for scrollable content with visual aesthetics. This property lets us control how thick scrollbars appear, making them more subtle without sacrificing functionality.

The scrollbar-width property accepts three values:


Scroll each container to see how different scrollbar-width values affect the interface. Notice how 'thin' provides a balanced compromise between aesthetics and usability.

scrollbar-width: auto

scrollbar-width: thin

scrollbar-width: none

⚠️ While 'none' might seem appealing, it can impact accessibility. I recommend using 'thin' for a better user experience.

The space where a scrollbar lives is called the scrollbar gutter - it sits between the inner border edge and outer padding edge of an element. browsers handle this space in two different ways:

  • Classic scrollbars: Take up actual space in your layout
  • Overlay scrollbars: Float on top of your content (common on macOS)

The scrollbar-gutter property lets us control how browsers handle this space. It accepts three values:


When should you use scrollbar-width or scrollbar-gutter?

They’re most useful in components where content length changes often - exactly where you don’t want things jumping around or shifting.

scrollbar-width works great for

  • Keeping chat message lists readable with a thin scrollbar
  • Sidebars like in VS Code where you want subtle scrolling
  • Data grids with lots of rows but limited vertical space
  • Making a Spotify-style horizontal media scroller look polished

scrollbar-gutter really shines when

  • Building a messenger app where new messages keep coming in
  • Creating modals with dynamic content that might need scrolling
  • Making data tables where rows get added or removed often
  • Handling sidebar navigation that expands and collapses

The key is using them together in places where content is dynamic and you want smooth scrolling without layout surprises. Nothing’s worse than clicking something just as the page shifts because a scrollbar popped in.

Word of caution: These properties are powerful, but that doesn’t mean every scrollbar needs customizing. Users have muscle memory for how scrollbars work. Only tweak scrollbars when it genuinely improves the user experience - like preventing those annoying layout jumps or cleaning up a cluttered interface.

If you found this article helpful, you might enjoy my free newsletter. I share developer tips and insights to help you grow your skills and career.


More Articles You Might Enjoy

If you enjoyed this article, you might find these related pieces interesting as well. If you like what I have to say, please check out the sponsors who are supporting me. Much appreciated!

Webdev
4 min read

Self-Taught Developer's Guide to Thriving in Tech

How to turn your non-traditional background into your biggest asset

Sep 28, 2024
Read article
Webdev
8 min read

Stop Using localStorage for Sensitive Data: Here's Why and What to Use Instead

Understanding the security risks of localStorage and what to use instead for tokens, secrets, and sensitive user data

Oct 28, 2024
Read article
Webdev
6 min read

Inside the CSS Engine: CSSOM Explained

A deep dive into how browsers parse and manipulate CSS, its impact on web performance, and why it matters

Oct 25, 2024
Read article
Webdev
3 min read

align-content: The Simplest Way to Center Content with CSS

Finally, we can center things in block layouts without flexbox gymnastics

Dec 13, 2024
Read article
Webdev
3 min read

CSS ::target-text for Text Highlighting

A look at how browsers can highlight text fragments using CSS ::target-text, making text sharing and navigation more user-friendly

Dec 17, 2024
Read article
Webdev
7 min read

Tips for Reducing Cyclomatic Complexity

Cyclomatic complexity is like counting how many ways a car can go. More options make it harder to drive because you have to make more decisions, which can lead to confusion.

Sep 10, 2024
Read article
Webdev
3 min read

CSS :has() - The Parent Selector We've Always Wanted

Transform your CSS with :has(), the game-changing selector that finally lets us style elements based on their children.

Dec 4, 2024
Read article
Webdev
4 min read

Speed Up Your Website With rel='preconnect' and increase PageSpeed Insights Score

Using link rel='preconnect' can improve your website's performance by reducing connection setup times to key external domains.

Sep 13, 2024
Read article
Webdev
8 min read

Become a Web Developer in 180 Days

A comprehensive roadmap to becoming a proficient web developer

Oct 29, 2019
Read article

This article was originally published on https://www.trevorlasn.com/blog/css-scrollbar-width-and-scrollbar-gutter. It was written by a human and polished using grammar tools for clarity.