Monday, September 30, 2013

Custom scrollbars for IE, Chrome and Firefox using CSS

Custom scrollbars

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

body{
  scrollbar-base-color: #C0C0C0;
  scrollbar-base-color: #C0C0C0;
  scrollbar-3dlight-color: #C0C0C0;
  scrollbar-highlight-color: #C0C0C0;
  scrollbar-track-color: #EBEBEB;
  scrollbar-arrow-color: black;
  scrollbar-shadow-color: #C0C0C0;
  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 scrollbars for IE, Chrome and Firefox using CSS

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

::-webkit-scrollbar { width: 3px; height: 3px;}
::-webkit-scrollbar-button {  background-color: #666; }
::-webkit-scrollbar-track {  background-color: #999;}
::-webkit-scrollbar-track-piece { background-color: #ffffff;}
::-webkit-scrollbar-thumb { height: 50px; background-color: #666; border-radius: 3px;}
::-webkit-scrollbar-corner { background-color: #999;}}
::-webkit-resizer { background-color: #666;}

There's also a scrollbar pieces map for you:

Custom scrollbars for IE, Chrome and Firefox using CSS

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

@-moz-document url-prefix(http://),url-prefix(https://) {
scrollbar {
   -moz-appearance: none !important;
   background: rgb(0,255,0) !important;
}
thumb,scrollbarbutton {
   -moz-appearance: none !important;
   background-color: rgb(0,0,255) !important;
}

thumb:hover,scrollbarbutton:hover {
   -moz-appearance: none !important;
   background-color: rgb(255,0,0) !important;
}

scrollbarbutton {
   display: none !important;
}

scrollbar[orient="vertical"] {
  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.

via CodeMug by