WebKit-based browsers (Chrome, Edge, Safari, Opera) allow developers to fully customize scrollbars using a set of
::-webkit-scrollbar pseudo-elements. These give you control over width, thumb, track, buttons, and even corner areas of the scrollbar.
Note
β Not supported in Firefox (use scrollbar-color instead)
β Great for dashboards, chat apps, editors, or themed UI
π¦ List of WebKit Scrollbar Selectors
| Selector | Description |
|---|---|
| ::-webkit-scrollbar | Styles the overall scrollbar (width/height) |
| ::-webkit-scrollbar-thumb | Draggable element inside the scrollbar |
| ::-webkit-scrollbar-track | Background track where the thumb slides |
| ::-webkit-scrollbar-track-piece | Each part of the track not occupied by the thumb |
| ::-webkit-scrollbar-button | Arrow buttons at top/bottom (rarely visible today) |
| ::-webkit-scrollbar-corner | Corner area where vertical & horizontal scrollbars meet |
π¨ 1. Base Scrollbar Styling
Base scrollbar
.scroll-box::-webkit-scrollbar {
width: 12px; /* vertical scrollbar width */
height: 12px; /* horizontal scrollbar height */
}Use width and height to size your scrollbars.
π¨ 2. Style the Scrollbar Thumb
Thumb
.scroll-box::-webkit-scrollbar-thumb {
background: #555;
border-radius: 8px;
}The thumb is the draggable part inside the track.
π¨ 3. Style the Scrollbar Track
Track
.scroll-box::-webkit-scrollbar-track {
background: #e0e0e0;
}The track is the background where the thumb slides.
π¨ 4. Style the Scrollbar Track Piece
Track piece
.scroll-box::-webkit-scrollbar-track-piece {
background: #f5f5f5;
}Applies to specific sections of the track (above/below thumb).
π¨ 5. Style Scrollbar Buttons
Scrollbar buttons
.scroll-box::-webkit-scrollbar-button {
background: #ccc;
height: 12px;
}Many modern browsers hide arrow buttons, but styling is still supported.
π¨ 6. Style the Scrollbar Corner
Scrollbar corner
.scroll-box::-webkit-scrollbar-corner {
background: #ddd;
}This covers the little square where horizontal and vertical scrollbars meet.
π¦ Full Example: Custom Scrollbar Theme
Full WebKit scrollbar theme
.scroll-area {
overflow: auto;
}
/* "Main" scrollbar area */
.scroll-area::-webkit-scrollbar {
width: 12px;
}
/* Background track */
.scroll-area::-webkit-scrollbar-track {
background: #eee;
}
/* Draggable thumb */
.scroll-area::-webkit-scrollbar-thumb {
background: #888;
border-radius: 6px;
}
/* Hover effect */
.scroll-area::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Track piece */
.scroll-area::-webkit-scrollbar-track-piece {
background: #f7f7f7;
}
/* Scrollbar buttons */
.scroll-area::-webkit-scrollbar-button {
background: #ccc;
}
/* Corner square */
.scroll-area::-webkit-scrollbar-corner {
background: #ddd;
}π§ͺ Real-World Use Cases
1οΈβ£ Code Editors
Editor scrollbar
.editor::-webkit-scrollbar-thumb {
background: #444;
}2οΈβ£ Chat Apps
Chat list
.chat::-webkit-scrollbar {
width: 6px;
}3οΈβ£ Dashboard Panels
Dashboard
.panel::-webkit-scrollbar-thumb {
background: #3498db;
}β οΈ Common Mistakes
- β Forgetting these work only in WebKit browsers
- β Setting -webkit-scrollbar without overflow
- β Overstyling (makes UI distracting)
- β Using extremely small scrollbar widths (hurts accessibility)
Note
π₯ Summary
WebKit scrollbar pseudo-elements allow deep customization of scrollbars in modern Chromium & Safari browsers. Combined with Firefoxβs scrollbar properties, you can create beautiful, consistent scrollbars across platforms.