Since the early days of the web, customizing the browser’s scrollbar has proven to be very difficult to standardize across major browsers. Fortunately, on September 2018 a W3C Working Draft called CSS Scrollbars was released that looks like a viable way to finally accomplish this!
As of 2020, 96% of internet users are running browsers that support CSS scrollbar styling, but you will need to write two sets of CSS rules to cover Firefox, Webkit and Chromium browsers.
Let’s jump into some code samples!
Styling scrollbars for Chrome/Edge/Safari is available behind the vendor prefix -webkit-scrollbar
width: 12px; /* width of the entire scrollbar */
background: orange; /* color of the tracking area */
background-color: blue; /* color of the scroll thumb */
border-radius: 20px; /* roundness of the scroll thumb */
border: 3px solid orange; /* creates padding around scroll thumb */
But there’s good news… And bad news:
Good news! This code works perfectly fine in the latest releases of Chrome/Edge/Safari!
Bad news? Unfortunately, this spec has been formally abandoned by W3C so we can expect it to be slowly deprecated in the coming years.
Microsoft Edge officially switched to the Chromium V8 engine on January 2020!
Firefox is a champion of new W3C standards, and they’re always willing to try out emerging APIs. As such, the new CSS Scrollbars features are already available in normal releases of Firefox:
scrollbar-width: thin; /* "auto" or "thin" */
scrollbar-color: blue orange; /* scroll thumb & track */
Sweet! You might have noticed a few differences compared to the deprecated
Firstly, it’s way more concise! And secondly, it lacks features like creating a padding and roundness for the “track thumb”. Since the spec is still changing, these missing features could likely get included.
The Way Forward
How do we style scrollbars considering there isn’t a single, authoritative API? Just combine both approaches!
/* The emerging W3C standard
that is currently Firefox-only */
scrollbar-color: blue orange;
/* Works on Chrome/Edge/Safari */
border: 3px solid orange;
Once -webkit-scrollbar is deprecated, you can fallback on the new CSS Scrollbars standard without missing a beat.
Interactive demo below:
See the Pen abORvVW by alligatorio (@alligatorio) on CodePen.
Try switching to a different browser to see it working. Supports the latest Firefox/Chrome/Safari/Edge releases.