CSS Scrollbar Styling: Standard Properties vs WebKit
Customizing scrollbars in modern web design is split between two
distinct approaches: the standard W3C properties
(scrollbar-width and scrollbar-color) and the
legacy, vendor-prefixed ::-webkit-scrollbar
pseudo-elements. This article breaks down the fundamental differences
between these two methods, highlighting their syntax, level of
customization, browser compatibility, and how to implement them
effectively.
The
Standard Properties: scrollbar-width and
scrollbar-color
The W3C CSS Scrollbars Module Level 1 introduced standardized properties to control scrollbar appearance without exposing complex internal browser components.
scrollbar-width: Controls the thickness of the scrollbar. It accepts three predefined keyword values:auto: The default platform scrollbar width.thin: A narrower scrollbar variant provided by the platform.none: Completely hides the scrollbar while keeping the element scrollable.
scrollbar-color: Controls the color palette of the scrollbar. It takes two color values: the first applies to the scrollbar thumb (the moving handle), and the second applies to the scrollbar track (the background).- Example:
scrollbar-color: #888 #f1f1f1;
- Example:
Advantages:
- Official web standard supported natively across modern browsers (Firefox, Chrome, Edge, Safari).
- Lightweight, minimal, and performance-friendly.
- Prevents developers from accidentally breaking platform accessibility affordances.
Limitations:
- Extremely limited visual styling. You cannot adjust exact pixel
widths, borders, border-radius, shadows, or pseudo-states like
:hoveron individual scrollbar sub-elements.
The WebKit Pseudo-Elements
Before standardization, WebKit introduced a set of pseudo-elements that expose the internal DOM tree of the scrollbar in Blink- and WebKit-based browsers (Chrome, Edge, Safari, Opera).
Key pseudo-elements include:
::-webkit-scrollbar: The entire scrollbar container (controls width and height in pixels).::-webkit-scrollbar-track: The background track where the thumb moves.::-webkit-scrollbar-thumb: The draggable scrolling handle.::-webkit-scrollbar-button: Up/down/left/right directional buttons.::-webkit-scrollbar-corner: The bottom corner where horizontal and vertical scrollbars meet.
Advantages:
- Fine-grained control over layout and appearance using standard CSS
box-model properties (e.g.,
border-radius,box-shadow, gradients, pixel dimensions). - Supports interactive states such as
::-webkit-scrollbar-thumb:hoverand::-webkit-scrollbar-thumb:active.
Limitations:
- Non-standard and proprietary.
- Never supported by Firefox.
- More verbose and prone to deprecation or inconsistency as rendering engines evolve.
Key Differences at a Glance
| Feature | Standard (scrollbar-*) |
WebKit
(::-webkit-scrollbar-*) |
|---|---|---|
| Specification | Official W3C Standard | Proprietary / Non-standard |
| Firefox Support | Full support | No support |
| Chrome/Safari/Edge | Supported in modern versions | Supported (legacy compatibility) |
| Customization Depth | Colors and predefined widths only | Pixel sizing, borders, shadows, hover states |
| Syntax Complexity | Low (two CSS properties) | High (multiple pseudo-elements) |
Recommended Implementation Strategy
For modern web development, the recommended pattern combines both approaches using progressive enhancement. Declare the standard properties first to ensure consistent, forward-compatible behavior across all engines, and supplement with WebKit pseudo-elements if advanced design requirements demand precise pixel control on Chromium and WebKit browsers:
/* Custom scrollable container */
.scroll-container {
overflow-y: auto;
/* Standard properties (Firefox, modern Chrome/Safari/Edge) */
scrollbar-width: thin;
scrollbar-color: #555 #e0e0e0;
}
/* WebKit-specific enhancements for fine-grained styling */
.scroll-container::-webkit-scrollbar {
width: 8px;
}
.scroll-container::-webkit-scrollbar-track {
background: #e0e0e0;
}
.scroll-container::-webkit-scrollbar-thumb {
background-color: #555;
border-radius: 4px;
}
.scroll-container::-webkit-scrollbar-thumb:hover {
background-color: #333;
}By prioritizing the standard properties, your design remains maintainable and resilient against future browser engine updates while still looking polished.