Scrollbars are an essential component of any website that contains lengthy content. They provide users with a way to navigate through the content with ease. While browsers come with default scrollbar styles, they may not always match the design of your website. This is where CSS scrollbar selectors come in.
There are multiple CSS pseudo-elements that allows us to customize elements scrollbar on WebKit and Blink based browsers.
Here is a quick reminder of the available pseudo-elements:
You can add these pseudo-elements to any element that has content which is longer than the space reserved for the element.
Note: Elements overflow property must be set to scroll . Othervice no scrollbar is displayed.
It is worth noting that the selectors mentioned above only work in Blink and WebKit based browsers like Google Chrome and Safari. For other browsers, you can use the scrollbar selectors provided by the W3C, such as scrollbar-width, scrollbar-color , scrollbar-track-color , scrollbar-thumb-color , and scrollbar-face-color .
Supported browsers include:
In conclusion, CSS scrollbar selectors provide web developers with a way to customize the appearance of scrollbars and make them match the design of their websites. By using these selectors, you can create a more cohesive and aesthetically pleasing user experience for your visitors.
body { --sb-track-color: #23769C; --sb-thumb-color: #43da86; --sb-size: 10px; scrollbar-color: var(--sb-thumb-color) var(--sb-track-color); } body::-webkit-scrollbar { width: var(--sb-size); } body::-webkit-scrollbar-track { background: var(--sb-track-color); border-radius: 5px; } body::-webkit-scrollbar-thumb { background: var(--sb-thumb-color); border-radius: 5px; border: 0px solid #232E33; }