Technology News

Strut Your Stuff With a Custom Scrollbar

The first time I had my breath taken away by a humble scrollbar was on this very site. When CSS-Tricks v17 rolled out with its FAT CHONKY BOI, my jaw dropped.

I didn’t know you could do that on a professional site. And it would look… good?!

I appreciated so much about it—the gentle gradient, the reckless rounding, the blended background, the sheer satisfying CHONKINESS that dares you to click and wiggle it up and down just to marvel in its tactile heft. How bold! How avant-garde! What sheer, accessible, gracefully degrading delight!

Of course, because fun doesn’t last, the current CSS Tricks scrollbar is more grown-up and muted, light gray on black. Still on brand, still flexing subtle gradient muscle, but not so distracting that it detracts from the reading experience. In our ultra-functional world of MVPs and 80/20 rules, maximizing efficiency and hacking productivity, custom scrollbars evince something about craftsmanship. It says with no words what you can’t in a hundred.

Thanks to some standardization (with more on the way), the API is simple: seven pseudo-elements and eleven pseudo-classes that target (almost) every imaginable component and state of the trusty (and often overlooked) scrollbar. Sounds like a lot, but you can go very far with just three of them:

body::-webkit-scrollbar { /* required - the "base" of the bar - mostly for setting width */
} body::-webkit-scrollbar-track { /* the "track" of the bar - great for customizing "background" colors */
} body::-webkit-scrollbar-thumb { /* the actual draggable element, the star of the show! */
}

From here, it works like any other selected element, so bring your full bag of single div CSS tricks! Media queries work! Background gradients work! Transparency works! Margins with all manner of CSS units work! (Not everything works… I’d love to style cursor on my scrollbars for that authentic GeoCities look). I tried it out on my site with Lea Verou’s stash of CSS background gradients (my stash of stashes is here) and ended up with an atrocious combo of stripy barber pole (????) for the thumb element and transparent hearts for the track. But it was most definitely mine—so much so that people have taken to calling it the “swyxbar” when I implemented a subtler version at work.

Every front-end developer should take this too far at least once in their careers. Live dangerously! Break the rules! Rage against the user agent! And maybe don’t ship scrollbars that break user expectations on a mass-market product (like Google Wave did back in the day)!

Care for the Text
The space station race

Related Articles

7 Easy Steps to Get Professional Web Design Services

acemero-blog-3-1180x664
Technical considerations like wireframes, programming, and content management are frequently at the forefront of web designers’ minds when thinking about web design services. Effective design goes beyond flashy aesthetics or…

Netlify Has Scheduled Functions

netlify-has-scheduled-functions
Hey! Scheduled Functions are cool! Think of them like a CRON job. I want this code to run every Monday at 2pm. I want this code run every hour on…

A Guide to Python Exception Handling

A Guide to Python Exception Handling
In this article, we’ll look at how to handle errors and exceptions in Python — a concept known as “exception handling”. There are usually two types of errors you’ll experience…

A Guide to Positive Reinforcement in UX Design

Exploring the Potential of the Metaverse: A New World Awaits
We love to point out others’ mistakes. However, what about providing positive feedback when a user completes a critical action? Often, applications lack positive feedback mechanisms that contribute to a…