{"id":375019,"date":"2022-11-14T05:54:26","date_gmt":"2022-11-14T13:54:26","guid":{"rendered":"https:\/\/css-tricks.com\/?p=375019"},"modified":"2022-11-14T05:54:27","modified_gmt":"2022-11-14T13:54:27","slug":"classy-and-cool-custom-css-scrollbars-a-showcase","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/classy-and-cool-custom-css-scrollbars-a-showcase\/","title":{"rendered":"Classy and Cool Custom CSS Scrollbars: A Showcase"},"content":{"rendered":"\n

In this article we will be diving into the world of scrollbars. I know, it doesn\u2019t sound too glamorous, but trust me, a well-designed page goes hand-in-hand with a matching scrollbar. The old-fashioned chrome scrollbar just doesn\u2019t fit in as much.<\/p>\n\n\n\n

We will be looking into the nitty gritty details of a scrollbar and then look at some cool examples.<\/p>\n\n\n\n\n\n\n

Components of a scrollbar<\/h3>\n\n\n

This is more of a refresher, really. There are a bunch of posts right here on CSS-Tricks<\/a> that go into deep detail when it comes to custom scrollbar styling in CSS.<\/p>\n\n\n\n

To style a scroll bar you need to be familiar with the anatomy of a scrollbar. Have a look at this illustration:<\/p>\n\n\n\n

\"A<\/figure>\n\n\n\n

The two main components to keep in mind here are:<\/p>\n\n\n\n

  1. The track<\/strong> is the background beneath the bar.<\/li>
  2. The thumb<\/strong> is the part that the user clicks and drags around.<\/li><\/ol>\n\n\n\n

    We can change the properties of the complete scrollbar using the vendor-prefixed::-webkit-scrollbar<\/code> selector. We can give the scroll bar a fixed width, background color, rounded corners\u2026 lots of things! If we\u2019re customizing the main scrollbar of a page, then we can use ::-webkit-scrollbar<\/code> directly on the HTML element:<\/p>\n\n\n\n

    html::-webkit-scrollbar {\n  \/* Style away! *\/\n}<\/code><\/pre>\n\n\n\n

    If we\u2019re customizing a scroll box that\u2019s the result of overflow: scroll<\/code>, then we can use ::-webkit-scrollbar<\/code> on that element instead:<\/p>\n\n\n\n

    .element::-webkit-scrollbar {\n  \/* Style away! *\/\n}<\/code><\/pre>\n\n\n\n

    Here\u2019s a quick example that styles the HTML element\u2019s scrollbar so that it is wide with a red background:<\/p>\n\n\n\n