Style custom scrollbars for webkit browsers
Quick Answer
Use `::-webkit-scrollbar`, `::-webkit-scrollbar-track`, and `::-webkit-scrollbar-thumb` pseudo-elements to fully customise scrollbar appearance in Chrome and Safari.
1.custom-scrollbar::-webkit-scrollbar {
2 width: 8px;
3}
4
5.custom-scrollbar::-webkit-scrollbar-track {
6 background: #f1f1f1;
7 border-radius: 10px;
8}
9
10.custom-scrollbar::-webkit-scrollbar-thumb {
11 background: #888;
12 border-radius: 10px;
13}
14
15.custom-scrollbar::-webkit-scrollbar-thumb:hover {
16 background: #555;
17}The ::-webkit-scrollbar family of pseudo-elements lets you fully style scrollbars in Chromium-based browsers and Safari. You can control the width, track background, thumb color, border-radius, and hover states. Firefox uses the simpler scrollbar-width and scrollbar-color properties for a cross-browser approach.
Firefox supports `scrollbar-width: thin | auto | none` and `scrollbar-color: thumbColor trackColor` as standard CSS properties. Add them alongside the `::-webkit-scrollbar` rules for cross-browser coverage.
This free css code snippet for custom scrollbar is production-ready and copy-paste friendly. Whether you are building a web app, API, or frontend interface, this intermediate-level example will help you implement custom scrollbar quickly and correctly.
All snippets in the Snippetly library follow css best practices and are tested for real-world use. You can adapt this code to work with React, Vue, Node.js, or any project that uses css.
Organise your team's code snippets with Snippetly. Share knowledge and boost productivity across your organisation.