DigitalOcean provides cloud products for every stage of your journey. Get started with $200 in free credit!
A brief history of styling scrollbars:
- It used to be a thing only Internet Explorer could do (ancient versions) with stuff like
-ms-scrollbar-base-color
. These do not exist anymore. - Then WebKit-based browser engines got on board with stuff like
::-webkit-scrollbar
. That’s what this Alamanac entry mostly covers, as it works across the Safari/Chrome landscape today. - Standards have finally gotten involved, and those styling options are covered by un-prefixed properties like
scrollbar-color
andscrollbar-width
.
Styling scrollbars for the Safari/Chrome world is exposed behind the -webkit
vendor prefix.
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 {
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-scrollbar
addresses the background of the bar itself. It is usually covered by the other elements::-webkit-scrollbar-button
addresses the directional buttons on the scrollbar::-webkit-scrollbar-track
addresses the empty space “below” the progress bar::-webkit-scrollbar-track-piece
is the top-most layer of the the progress bar not covered by the draggable scrolling element (thumb)::-webkit-scrollbar-thumb
addresses the draggable scrolling element that resizes depending on the size of the scrollable element::-webkit-scrollbar-corner
addresses the (usually) bottom corner of the scrollable element, where two scrollbars might meet::-webkit-resizer
addresses the draggable resizing handle that appears above thescrollbar-corner
at 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.
Notes on usage
- 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-scrollbar
styles 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
-webkit
vendor prefix, several jQuery plugins have been written to “polyfill” or extend this functionality to other browsers. One such plugin is jScrollPane.
Browser support
This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.
Desktop
Chrome | Firefox | IE | Edge | Safari |
---|---|---|---|---|
121 | 64 | 11 | 121 | TP* |
Mobile / Tablet
Android Chrome | Android Firefox | Android | iOS Safari |
---|---|---|---|
126* | 127 | 126* | 13.4-13.7* |
scrollbar
CSS tricks that use CSS Scrollbar With Progress Meter
Custom Scrollbars in WebKit
Hide Scrollbars During an Animation
Designing for “Show scroll bars”
Eliminate “Jumps” in Horizontal Centering By Forcing a Scroll Bar
How To Create a Horizontally Scrolling Site
More Elegant Fix for Jumping Scrollbar Issue
Indicating Scroll Position on a Page With CSS
Scrollbar Reflowing
Scrollbars on Hover
Position Vertical Scrollbars on Opposite Side with CSS
Strut Your Stuff With a Custom Scrollbar
Pure CSS Horizontal Scrolling
That’s Just How I Scroll
`matrix3d()` for a Frame-Perfect Custom Scrollbar
scrollbar
Next steps with - The Current State of Styling Scrollbars (CSS-Tricks)
- Custom Scrollbars in WebkKit (CSS-Tricks)
- How To Customize the Browser’s Scrollbar with CSS (DigitalOcean)
- Two Browsers Walked Into a Scrollbar (Zach Leatherman)
- Surfin’ Safari: Styling Scrollbars (WebKit Blog)
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
it doesn’t works for mozilla firefox.
Nice example………. and this page has very very useful and wonderful features . especially this comment area is awesome!
your are awesome also.
No browser support for Firefox and is an open issue since 2001
0.0
Mkay
how will i be able to customize the browser’s right scrollbar using css????
Hi Martin ,
Firstly , thanks a lot for sharing this about using scrollbar , I created a scroll bar for my text content in my html app , and now the scroll bar looks and works fine , but the guy at my office who reviewed my UI said that the when the text content is scrolled , it appears as if the text is getting cut and displayed at the top or at the bottom . I actually tried to scroll the text in your example and feel the same .
DO you have any suggestion on how i can get rid of the text being shown as half cut when i scroll ??
thanks
Sabir
It is happening because the height of the body is set to 100%. try changing the height.
Let me know if I am getting your point here.
This websiteos is asomitos
Thank you you so much its very helpful to me :)
thank you nice information for front end developers
ThanQ boss, this example helped me in designing my website.
It’s nice. Better if run the firefox and IE.
Not working in Firefox & IE
asdasda
How can I apply original style to ::-webkit-scrollbar-button? Do I have to specify background image for it?
is there any way to increase the scroll bar width in IE 11?
nice helpfull
why can’t use :hover style for it? the facebook create hover style by using script…
Enjoyed reading this and tried it myself but the custom scrollbar did not render in Firefox, looks great in other browsers, any ideas?
thanks
Good example. approximately also implemented here on the website.
Not working in mozilla firefox
-moz- instead of webkit
not working on firebox browser……………
Android Chrome browser removed support since last December 2016. Doesn’t work now on android chrome but works on desktop chrome.
hello m not able to change the height of scroll bar thumb .how can I change it???
You can not change height of scroll thumb. It depends on height of body
Hi,
I want to show the scrollbar in the middle of the screen, 80% of the height.
Is there any possibility?
Thanks
How can a change the color of ::-webkit-scrollbar ?
When I toggle between Overflow: hidden and scroll, my page layout shifts. Do you know a way to make this toggle of on and off not affect my containers width/layout? Thanks! Awesome site I use it all the time.
Thank you! All works as should be https://clip2net.com/s/3RHC84j
Here is the plugin that you can use.
http://grsmto.github.io/simplebar/
Antonio J Figueroa – you can use CSS
body{overflow-y:overlay;}
, but be aware that overlay is non-standard property and only Chrome supports that.what are the chances there is something similar that will work on drop-down as well …
This article should be updated to include the styling options for firefox:
Styling scrollbars in Firefox is also possible (since v64) with
scrollbar-color
andscrollbar-width
.Examples are available at https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scrollbars
I’ve created this tiny script for easy scrollbar customization.
https://github.com/yairEO/fakescroll
Thanks! Very useful info, as always on css-tricks!