More CSS answers

by Danny
Published 2 min read

Use the standard scrollbar-color and scrollbar-width properties first, and keep the older ::-webkit-scrollbar pseudo-elements only as a fallback for older browsers.

The short answer

#

Use the standard properties. scrollbar-color takes two colours, the thumb and then the track, and scrollbar-width takes auto, thin or none. They work in Firefox and in Chrome and Edge from version 121, and Safari added scrollbar-color in Safari 26.2.


_10
.panel {
_10
overflow-y: auto;
_10
scrollbar-color: #8a8fa3 transparent; /* thumb, track */
_10
scrollbar-width: thin;
_10
}

Why it happens

#

For a long time there were two separate approaches. Firefox implemented the standard scrollbar-color and scrollbar-width properties from the CSS Scrollbars spec. Chrome, Edge and Safari used the non-standard ::-webkit-scrollbar pseudo-elements, which let you style the bar, thumb and track like normal boxes, with borders, radii and gradients.

That split is why older tutorials show both. Chrome and Edge added the standard properties in version 121, and Safari added scrollbar-color in 26.2. Safari support for scrollbar-width has been less clear, so check MDN's compatibility table if a thin bar matters on Apple devices.

One detail catches people out. In Chrome and Edge 121 and later, once you set scrollbar-color or scrollbar-width on an element, the browser ignores any ::-webkit-scrollbar rules for it. You get the standard styling or the legacy styling, never a mix.

The standard properties give you less control on purpose. You choose colours and a thinner variant; the browser and operating system decide the shape, the arrows and whether the bar overlays the content. That keeps scrollbars usable and consistent with the platform.

How to fix it

#

Use the standard properties

Set them on the element that scrolls. To style the main page scrollbar, set them on html.


_10
html {
_10
scrollbar-color: #6b7280 #f3f4f6;
_10
}
_10
_10
.sidebar {
_10
overflow-y: auto;
_10
scrollbar-width: thin;
_10
scrollbar-color: #9ca3af transparent;
_10
}

scrollbar-color is inherited, so setting it on html also styles nested scroll areas unless they override it.

Match light and dark themes

Use custom properties or light-dark() so the colours follow the theme, and set color-scheme so the browser picks matching default scrollbars where you do not style them.


_10
:root {
_10
color-scheme: light dark;
_10
scrollbar-color: light-dark(#9ca3af, #4b5563) transparent;
_10
}

Add a legacy fallback only for older browsers

If you need richer styling in older Safari versions, wrap the ::-webkit-scrollbar rules in a feature query so modern Chrome and Edge use the standard properties.


_14
@supports not (scrollbar-color: auto) {
_14
.panel::-webkit-scrollbar {
_14
width: 8px;
_14
}
_14
_14
.panel::-webkit-scrollbar-thumb {
_14
background: #8a8fa3;
_14
border-radius: 4px;
_14
}
_14
_14
.panel::-webkit-scrollbar-track {
_14
background: transparent;
_14
}
_14
}

Reserve space so layout does not jump

When content grows and a scrollbar appears, the content area gets narrower and the layout shifts. scrollbar-gutter: stable keeps the space reserved.


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

Common pitfalls

#
  • Mixing both approaches on one element and wondering why the ::-webkit-scrollbar rules do nothing in Chrome. The standard properties take over.
  • Putting the styles on the wrong element. They belong on the element with overflow: auto or scroll, not its parent.
  • Making the thumb hard to see. Keep enough contrast between thumb and track, especially with thin.
  • Using scrollbar-width: none on content people need to scroll with a mouse. It hides the only visual clue that there is more.
  • Expecting a scrollbar on macOS when the system setting shows scrollbars only while scrolling. The overlay behaviour comes from the operating system.
#

Was this resource helpful?