How to Create a CSS-Tricks Custom Scrollbar

By  on  

Chris Coyier of CSS-Tricks is an amazing engineer and blogger. He's not only creative but has always had the drive to put his thoughts to work, no matter how large. He also has a good eye for the little things that can make CSS-Tricks or your site special. One of those little things is his custom scrollbar -- let's have a look at how it's done!

To create this excellent scrollbar effect, you'll need to employ three CSS selectors and the styling of your choosing:

/* Sets the dimensions of the entire scrollbar */
html::-webkit-scrollbar {
    width: 30px;
    height: 30px;
}

/* The grabbable scrollbar button  */
html::-webkit-scrollbar-thumb {
    background: -webkit-gradient(linear,left top,left bottom,from(#ff8a00),to(#e52e71));
    background: linear-gradient(180deg,#ff8a00,#e52e71);
    border-radius: 30px;
    box-shadow: inset 2px 2px 2px hsla(0,0%,100%,.25), inset -2px -2px 2px rgba(0,0,0,.25);
}

/* The vertical scrollbar background */
html::-webkit-scrollbar-track {
    background: linear-gradient(90deg,#201c29,#201c29 1px,#100e17 0,#100e17);
}

A few important notes: obviously you can create your own gradient colors but, more importantly, this scrollbar works only in Chrome, Safari, and Edge.

You need to be careful with these types of small customizations. When done well, they add to your branding and design. When done poorly, you confuse your user. Happy styling!

Recent Features

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

  • By
    Multiple File Upload Input

    More often than not, I find myself wanting to upload more than one file at a time.  Having to use multiple "file" INPUT elements is annoying, slow, and inefficient.  And if I hate them, I can't imagine how annoyed my users would be.  Luckily Safari, Chrome...

  • By
    CSS pointer-events

    The responsibilities taken on by CSS seems to be increasingly blurring with JavaScript. Consider the -webkit-touch-callout CSS property, which prevents iOS's link dialog menu when you tap and hold a clickable element. The pointer-events property is even more JavaScript-like, preventing: click actions from doing...

Discussion

  1. That is a very useful customization! As you said, proper execution is very necessary as a poorly executed customization can really harm your website. Thank you for sharing :)

  2. I’ve created this tiny script for easy scrollbar customization.

    https://github.com/yairEO/fakescroll

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!