courses.reviews logo
I launched a free website to help you find the best courses with reviews & discounts.
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.


Found this article helpful? You might enjoy my free newsletter. I share dev tips and insights to help you grow your coding skills and advance your tech career.

Interested in supporting this blog in exchange for a shoutout? Get in touch.


Liked this post?

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Webdev
3 min read

HTML Details Element: The Native Accordion You're Not Using

Discover how the HTML details element can replace your JavaScript accordions and why it might be better than your current solution

Dec 10, 2024
Read article
Webdev
3 min read

Native Popover Element with HTML

Create overlays and dropdowns easily with the native HTML popover API

Jan 24, 2025
Read article
Webdev
7 min read

How to Land Your First Tech Job

A developer's guide to tech interviews - from someone who sits on both sides of the table

Oct 24, 2024
Read article
Webdev
12 min read

Robust Data Fetching Architecture For Complex React/Next.js Apps

How I use the 'Three Layers of Data' architecture pattern for React and Next.js apps to avoid common pitfalls, tech debt, and improve performance

May 4, 2025
Read article
Webdev
4 min read

Remove Unnecessary NPM Packages with eslint-plugin-depend

We don't need packages to handle basic JavaScript tasks

Aug 13, 2024
Read article
Webdev
3 min read

CSS @supports: Write Future-Proof CSS

Detect CSS feature support and provide smart fallbacks with @supports

Dec 6, 2024
Read article
Webdev
6 min read

Micro Frontends: The LEGO Approach to Web Development

Explore the concept of micro frontends in web development, understand their benefits, and learn when this architectural approach is most effective for building scalable applications.

Oct 2, 2024
Read article
Webdev
4 min read

Open Dyslexic Font: Improve Your Web Accessibility

How to implement the Open-Dyslexic font to enhance readability for users with dyslexia

Oct 12, 2024
Read article
Webdev
5 min read

Add Auth to Astro 5 with Clerk in 5 Minutes

The simplest setup for adding Clerk authentication to your Astro project, with minimal code

Dec 18, 2024
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.