How to Create a CSS-Tricks Custom Scrollbar
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!
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 :)
I’ve created this tiny script for easy scrollbar customization.
https://github.com/yairEO/fakescroll