Using Custom scrollbars in your website can be really eye-catching and they go well with the website’s design. For web designers, it’s difficult creating them with JavaScript. Instead, you can create custom scrollbars using CSS. According to my acknowledge, it only worked in Internet Explorer. During my recent project, my client required the scrollbar to be stylized with CSS, and make it work in most mainstream browsers. So after a bit of googling, I found the tricks to do so and share them with you here.
Custom scrollbars for Internet Explorer
2 |
scrollbar-base- color : #C0C0C0 ; |
3 |
scrollbar-base- color : #C0C0C0 ; |
4 |
scrollbar -3 dlight- color : #C0C0C0 ; |
5 |
scrollbar-highlight- color : #C0C0C0 ; |
6 |
scrollbar-track- color : #EBEBEB ; |
7 |
scrollbar-arrow- color : black ; |
8 |
scrollbar-shadow- color : #C0C0C0 ; |
9 |
scrollbar-dark-shadow- color : #C0C0C0 ; |
In case you don’t know what these attributes mean, here is the scrollbar map that will help you understand.
custom scrollbar map for Internet Explorer
Use the above code for the tags you want to stylize, or use it in body, to stylize all scrollbars in the document. If you’re lazy enough to customize by yourself, there are some code generator you can use, this Custom Scrollbars Generator is nice.
Custom scrollbars for Chrome
1 |
::-webkit-scrollbar { width : 3px ; height : 3px ;} |
2 |
::-webkit-scrollbar-button { background-color : #666 ; } |
3 |
::-webkit-scrollbar-track { background-color : #999 ;} |
4 |
::-webkit-scrollbar-track-piece { background-color : #ffffff ;} |
5 |
::-webkit-scrollbar-thumb { height : 50px ; background-color : #666 ; border-radius: 3px ;} |
6 |
::-webkit-scrollbar-corner { background-color : #999 ;}} |
7 |
::-webkit-resizer { background-color : #666 ;} |
There’s also a scrollbar pieces map for you:
custom scrollbar map for Chrome
Obviously, Chrome and webkit based browsers can do more custom work than IE, not just colors, you can apply radius, transparency on scrollbars, that’s way more flexible than IE.
Custom scrollbars for Firefox
1 |
@-moz-document url-prefix(http://),url-prefix(https://) { |
3 |
-moz-appearance: none !important ; |
4 |
background : rgb ( 0 , 255 , 0 ) !important ; |
6 |
thumb,scrollbarbutton { |
7 |
-moz-appearance: none !important ; |
8 |
background-color : rgb ( 0 , 0 , 255 ) !important ; |
11 |
thumb:hover,scrollbarbutton:hover { |
12 |
-moz-appearance: none !important ; |
13 |
background-color : rgb ( 255 , 0 , 0 ) !important ; |
17 |
display : none !important ; |
20 |
scrollbar[orient= "vertical" ] { |
21 |
min-width : 15px !important ; |
The CSS code above for Firefox is a little different. But it can generate same custom scrollbars like Chrome do. And by using orient=”vertical” you can apply different styles for verticle and horzontal scrollbars, sounds like fun.
Though the css way of customization is simple, it does look a bit rough. Alternatively, you can use javascript-based scrollbars which give you more custom options. Remeber, it’s not necessary to change your website scrollbars, you should keep the design simple, not too fancy.