Click here to Skip to main content
6,595,444 members and growing! (20,971 online)
Email Password   helpLost your password?
Web Development » HTML / CSS » CSS     Intermediate

Manipulating scrollbar colors using CSS and JavaScript

By Ada Shimar

The thing about the default color of scrollbars is that they are dull and ugly. Wouldn't it be nice to change this color to better fit the overall theme of your site? See how to use Cascading Style sheets and JavaScript to do just that!
HTML, VC6Win2K, Visual Studio, Dev
Posted:4 Sep 2001
Views:156,850
Bookmarked:31 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
14 votes for this article.
Popularity: 3.98 Rating: 3.48 out of 5
3 votes, 33.3%
1

2
1 vote, 11.1%
3
2 votes, 22.2%
4
3 votes, 33.3%
5

Introduction

The thing about the default color of scrollbars is that it's dull and ugly. Usually this color is gray. Wouldn't it be nice to change this color to better fit the overall theme of your site? Luckily Cascading Style sheets and JavaScript can be used to do just that!

Using CSS

In CSS, you would just add this code to the top of your page to customize the browser's scrollbar colors: The great thing about CSS is that browsers that don't understand it will just skip it, in this case, Netscape browsers.

<style>
<!--
BODY{
scrollbar-face-color:#8080FF;
scrollbar-arrow-color:#FFFFFF;
scrollbar-track-color:#DDDDFF;
scrollbar-shadow-color:'';
scrollbar-highlight-color:'';
scrollbar-3dlight-color:'';
scrollbar-darkshadow-Color:'';
}
-->
</style>

Play around with the different values!

Using JavaScript

I can use JavaScript to dynamically change the scrollbar color. This is useful when I wish to do something more fancy, like alternating the scrollbar from one color to another. The code required is:

document.body.style.scrollbarFaceColor="colorname"
document.body.style.scrollbarArrowColor="colorname"
document.body.style.scrollbarTrackColor="colorname"
document.body.style.scrollbarShadowColor="colorname"
document.body.style.scrollbarHighlightColor="colorname"
document.body.style.scrollbar3dlightColor="colorname"
document.body.style.scrollbarDarkshadowColor="colorname"

A very good demonstration of this is a script written by Svetlin Staev, which changes the scrollbar colors when you move your mouse over and out of it: http://www.dynamicdrive.com/dynamicindex11/scrolleffect.htm

I'm seeing more and more sites customize the scrollbar color to blend in with the rest of their sites. Hope you find this tutorial useful in helping you do the same!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ada Shimar


Member

Location: United States United States

Other popular HTML / CSS articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
Questionis it working only for documents scroll bar ?? can i use for Panel scrollbar ?? PinmemberNirav Pate !20:21 22 Aug '08  
GeneralGood job! Pinmemberjoelperez10:27 7 Aug '08  
GeneralAbout Dreamweaver PinsussAnonymous1:47 14 May '05  
Generalin mozilla don´t work PinsussAnonymous11:25 12 Mar '05  
Generalhide horizontal scrollbar PinsussRayran8:12 6 May '04  
GeneralRe: hide horizontal scrollbar PinsussAnonymous10:41 25 May '04  
Generaltutotial? PinmemberMark Focas13:47 31 Aug '03  
GeneralRe: tutotial? PinmemberMember 43056772:09 1 Aug '08  
GeneralScrollbar width PinsussOnyxMax20:11 20 Jul '02  
GeneralRe: Scrollbar width PinsussAnonymous2:57 3 Dec '02  
GeneralCool ,Thanks... PinmemberJosh Knox20:03 20 Dec '01  
GeneralRequirements PinmemberPhilippe Lhoste5:49 11 Sep '01  
GeneralRe: Requirements PinmemberHockey12:51 19 Apr '02  
GeneralWhy? PinmemberRay Hayes2:14 5 Sep '01  
GeneralRe: Why? PinmemberAda Shimar9:51 5 Sep '01  
GeneralRe: Why? PinmemberPaul Watson21:16 11 Feb '02  
GeneralRe: Why? PinmemberDuc Truong14:43 21 Aug '02  
GeneralRe: Why? PinsussAnonymous2:53 16 Jun '04  
GeneralRe: Why? PinsussAnonymous8:04 20 Oct '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Sep 2001
Editor: Paul Watson
Copyright 2001 by Ada Shimar
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project