Custom Scrollbar CSS Generator

Style scrollbar width, track and thumb colors. The CSS covers the standard scrollbar-color property and the ::-webkit-scrollbar selectors Safari still needs.

Scroll this box to test your scrollbar. It scrolls both vertically and horizontally so you can check the thumb, track and corner.

Styling Scrollbars With CSS: scrollbar-color vs ::-webkit-scrollbar

Default scrollbars are often the last unstyled element on an otherwise polished page: a grey bar that clashes with a dark sidebar or a beige brand palette. CSS can restyle them, but there are two completely different systems, and browsers changed how they interact in 2024. Here’s how to write scrollbar CSS that works everywhere.

Custom styled CSS scrollbar with a rounded thumb in a scrollable panel

System 1: the standard properties

The CSS Scrollbars Styling specification defines two simple properties:

.panel {
  scrollbar-color: #8a6d3b #f3ecdf; /* thumb, then track */
  scrollbar-width: thin;            /* auto, thin or none */
}

That’s all you get: colors for the thumb and track, and a choice of normal or thin width (or hidden). No custom pixel widths, no rounded corners, no hover colors.

Firefox has supported these since version 64 (2018). Chrome and Edge added support in version 121 (early 2024). Safari has historically relied on the older WebKit approach.

System 2: the WebKit pseudo-elements

The older, non-standard approach styles the scrollbar as a set of pseudo-elements:

.panel::-webkit-scrollbar { width: 10px; height: 10px; }
.panel::-webkit-scrollbar-track { background: #f3ecdf; }
.panel::-webkit-scrollbar-thumb { background: #8a6d3b; border-radius: 10px; border: 2px solid #f3ecdf; }
.panel::-webkit-scrollbar-thumb:hover { background: #141414; }

This gives much finer control: exact width, rounded thumbs, padding (via a border in the track color), hover states and corner styling. It works in Chrome, Edge, Safari, Opera and other WebKit/Blink browsers, but not in Firefox.

The comparison

Featurescrollbar-color / scrollbar-width::-webkit-scrollbar
StandardYes (W3C spec)No (vendor extension)
FirefoxYesNo
Chrome / EdgeYes (121+)Yes
SafariLimited / recentYes
Custom pixel widthNo (auto, thin, none)Yes
Rounded thumb, hover, paddingNoYes

The Chrome 121 catch

Here is the change that broke many sites’ custom scrollbars: in Chromium, if an element has scrollbar-color or scrollbar-width set (other than auto), the ::-webkit-scrollbar styles are ignored for that element. So a common “cover all browsers” snippet that sets both systems on the same selector suddenly lost its rounded, custom-width scrollbars in Chrome, falling back to the simpler standard styling.

The fix is to give the standard properties only to browsers that don’t support the WebKit pseudo-elements:

@supports not selector(::-webkit-scrollbar) {
  .panel { scrollbar-color: #8a6d3b #f3ecdf; scrollbar-width: thin; }
}

Firefox gets the standard version; WebKit and Blink browsers keep the detailed pseudo-element styling. This is the pattern the scrollbar generator above outputs.

Alternatively, if you are happy with the simpler standard look, use only scrollbar-color and scrollbar-width and drop the WebKit rules. That is the most future-proof option.

Mobile and overlay scrollbars

On iOS, Android and macOS (with the default “show scroll bars when scrolling” setting), scrollbars are overlay scrollbars: thin, temporary bars that appear over content while scrolling and take up no layout space. Most custom styling has little or no effect on them, which is fine; they already stay out of the way.

On Windows and Linux desktop browsers, classic scrollbars take up space (usually around 15–17px) next to content. This has a layout consequence: 100vw includes the scrollbar width, so a width: 100vw element causes horizontal scrolling. Use width: 100% instead, or reserve space consistently with scrollbar-gutter: stable, which prevents the layout from shifting when content grows long enough to need a scrollbar.

Hiding scrollbars

Sometimes you want scrolling without a visible bar, for example in a horizontal carousel:

.carousel { scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }

Use this carefully. A visible scrollbar tells users that more content exists and how much. If you hide it, provide another cue: arrow buttons, partially visible next items, or dots.

Accessibility guidelines

  • Contrast: the thumb should be clearly visible against the track. WCAG’s 3:1 non-text contrast guideline is a sensible target for anything users need to see to operate.
  • Size: very thin scrollbars (under about 8px) are hard to grab with a mouse, especially for people with tremors or reduced dexterity. If you go thin, make the thumb wider on hover.
  • Don’t hide scrollbars on content users need to know is scrollable.
  • Forced colors: in Windows High Contrast mode, browsers use system colors for scrollbars. Don’t fight this.
  • Keyboard scrolling must still work. Scrollable regions that aren’t focusable may need tabindex="0" so keyboard users can scroll them, and an accessible name if they are significant regions.

Which scrollbar style suits which context

ContextSuggested style
Light pageTrack transparent or very light tint, thumb a mid-tone neutral
Dark sidebar or code blockDark track, thumb a lighter grey with hover brightening
Brand accentThumb in a muted version of your brand color, not the full saturation
Dense data tablesKeep standard width for easy grabbing

Style scrollbars inside components (sidebars, chat panels, code blocks, modals) rather than the whole page if you want the effect to stay subtle. Many users are used to their system’s page scrollbar.