scrollbar
The scrollbar set of CSS properties is a proprietary style hook from Internet Explorer 5.5, which let designers create custom themes for the browser's native scrollbars. Currently, it is exposed behind the -webkit vendor prefix for use in browsers using the Webkit (and Blink) rendering engine. This almanac entry is an overview, for a more complete breakdown of working with custom scrollbars, please read this CSS-Tricks article.
body::-webkit-scrollbar {
width: 1em;
}
body::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
body::-webkit-scrollbar-thumb {
background-color: darkgrey;
outline: 1px solid slategrey;
}
The -webkit-scrollbar family of properties consists of seven different pseudo-elements that, together, comprise a full scrollbar UI element:
::-webkit-scrollbaraddresses the background of the bar itself. It is usually covered by the other elements::-webkit-scrollbar-buttonaddresses the directional buttons on the scrollbar::-webkit-scrollbar-trackaddresses the empty space “below” the progress bar::-webkit-scrollbar-track-pieceis the top-most layer of the the progress bar not covered by the draggable scrolling element (thumb)::-webkit-scrollbar-thumbaddresses the draggable scrolling element that resizes depending on the size of the scrollable element::-webkit-scrollbar-corneraddresses the (usually) bottom corner of the scrollable element, where two scrollbars might meet::-webkit-resizeraddresses the draggable resizing handle that appears above thescrollbar-cornerat the bottom corner of some elements
In addition to these pseudo-elements, there are also eleven pseudo-selector classes that aren't required, but provide designers with the power to style various states and interactions of the scrollbar UI. A full breakdown of those pseudo-selectors, and a detailed example, can be found in this CSS-Tricks article.
Check out this Pen!
Points of Interest
- If there is no qualifying selector preceding the various pseudo-elements, the styles will apply to any scrollbar that may appear on the page.
- Setting
-webkit-scrollbarstyles is a good way to force your webpage to show horizontal or vertical scrollbars on versions of Mac OS newer than Lion, on which scrollbars are usually hidden by default. - Since this property is behind a
-webkitvendor prefix, several jQuery plugins have been written to “polyfill” or extend this functionality to other browsers. One such plugin is jScrollPane.
Other Resources
- CSS-Tricks: Custom Scrollbars in Webkit
- Surfin’ Safari: Styling Scrollbars
- jScrollPane
- -webkit-scrollbar on OSX
Browser Support
| Chrome | Safari | Firefox | Opera | IE | Android | iOS |
|---|---|---|---|---|---|---|
| yep | yep | nope | 15+ | nope | yep | yep |
No more information on this and other properties? I mean you can provide some examples or illustration on these properties.
This property is rather antique. It used to work in IE 5.5
http://css-tricks.com/custom-scrollbars-in-webkit/