Published By Joshua Sandoval

Twitter Facebook CSS WebKit Scrollbars


Scrollbar icon

​I know this all old information at this point, but custom CSS scrollbars are still pretty cool. Now, customisable scrollbars go pretty far back… even to IE5.5 with non-standard properties, but nowadays it's sorta more standard, being -webkit- prefixed and is part of the "Shadow DOM".

​The individual parts:

::-webkit-scrollbar /* 1 */ ::-webkit-scrollbar-track /* 2 */ ::-webkit-scrollbar-track-piece /* 3 */ ::-webkit-scrollbar-thumb /* 4 */ ::-webkit-scrollbar-button /* 5 */ ::-webkit-scrollbar-corner /* 6 */ ::-webkit-resizer /* 7 */
Scrollbar parts

​The different "pseudo states":

:horizontal :vertical :decrement :increment :start :end :double-button :single-button :no-button :corner-present :window-inactive

​Now, to be honest, this whole next section is getting ripped from Chris Coyier's post, who also ripped it off David Hyatt's Post a few years back from the WebKit blog, because he explains it very well. I'm sorry, I can't always be original. 😉

:horizontal – The horizontal pseudo-class applies to any scrollbar pieces that have a horizontal orientation.

:vertical – The vertical pseudo-class applies to any scrollbar pieces that have a vertical orientation.

:decrement – The decrement pseudo-class applies to buttons and track pieces. It indicates whether or not the button or track piece will decrement the view’s position when used (e.g., up on a vertical scrollbar, left on a horizontal scrollbar).

:increment – The increment pseudo-class applies to buttons and track pieces. It indicates whether or not a button or track piece will increment the view’s position when used (e.g., down on a vertical scrollbar, right on a horizontal scrollbar).

:start – The start pseudo-class applies to buttons and track pieces. It indicates whether the object is placed before the thumb.

:end – The end pseudo-class applies to buttons and track pieces. It indicates whether the object is placed after the thumb.

:double-button – The double-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is part of a pair of buttons that are together at the same end of a scrollbar. For track pieces it indicates whether the track piece abuts a pair of buttons.

:single-button – The single-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is by itself at the end of a scrollbar. For track pieces it indicates whether the track piece abuts a singleton button.

:no-button – Applies to track pieces and indicates whether or not the track piece runs to the edge of the scrollbar, i.e., there is no button at that end of the track.

:corner-present – Applies to all scrollbar pieces and indicates whether or not a scrollbar corner is present.

:window-inactive – Applies to all scrollbar pieces and indicates whether or not the window containing the scrollbar is currently active. (In recent nightlies, this pseudo-class now applies to ::selection as well. We plan to extend it to work with any content and to propose it as a new standard pseudo-class.)


​An good example:

​​(…with given code)


LoadstarCode scrollbar

A good example of a custom CSS scrollbar is well… ​LoadstarCode's scrollbar, it's lightweight and changes when "Night Mode" is active. Pretty neat, huh?

Here's a downloadable CSS file containing the code. (I'm doing this because it would be a nightmare formatting this into a code element, especially if I need to edit it…)

Download CSS file

​…Unfortunately, CSS scrollbars are pretty rare in the wild, and also I can't just rip code off other people's sites… so you'll have to deal with what I can throw down on the table.

​Scrollbar Plugins/Polyfills

​A list of Polyfills/plugins for non-supporting browsers:

​Here are just a few javascript scrollbar plugins:

​You'll want to use one of these if a custom scrollbar is mandatory for your design and has to work on all operating systems and browser variants.

​Addendum: WebKit overflow-scrolling

​And while we're on the subject of scrollbars, let's talk about a nifty WebKit specific CSS property: -webkit-overflow-scrolling. This CSS property was introduced in iOS 5 (so it's pretty well supported), and although it replaces your awesome custom scrollbar on iOS, it adds momentum scrolling, which is pretty awesome. There's not much to talk about when it comes to this property, so here are potential values:


​/* Does not allow for momentum scrolling, but… it allows you to keep your CSS scrollbar! */ ​-webkit-overflow-scrolling: auto;
​/* This value allows for momentum scrolling! */ ​-webkit-overflow-scrolling: touch;