CSS scrollbar-color Property
The CSS scrollbar-color property specifies the colors of a scrollbar's thumb and track.
It allows developers to customize scrollbar colors while retaining the browser's native scrolling functionality. The property accepts auto or two color values, with the first color applied to the thumb and the second to the track.
scrollbar-color Syntax
The scrollbar-color property accepts the keyword auto or two CSS color values separated by a space.
Basic Syntax
selector {
scrollbar-color: thumb-color track-color;
}
The first color styles the scrollbar thumb. The second color styles the scrollbar track.
Available Values
.container {
scrollbar-color: auto;
}
.container {
scrollbar-color: #2563eb #e2e8f0;
}
.container {
scrollbar-color: navy lightgray;
}
.container {
scrollbar-color: rgb(37 99 235) rgb(226 232 240);
}
.container {
scrollbar-color: hsl(221 83% 53%) hsl(214 32% 91%);
}
CSS-Wide Keywords
.container {
scrollbar-color: initial;
}
.container {
scrollbar-color: inherit;
}
.container {
scrollbar-color: unset;
}
.container {
scrollbar-color: revert;
}
.container {
scrollbar-color: revert-layer;
}
Both colors must be supplied when using custom colors. A single color value is invalid.
Property Values
| Value | Description |
|---|---|
auto |
Allows the browser or operating system to determine scrollbar colors. This is the initial value. |
<color> <color> |
Specifies the thumb color followed by the track color. |
initial |
Resets the property to auto. |
inherit |
Uses the computed scrollbar colors from the parent element. |
unset |
Inherits the parent's value because the property is inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | Yes |
| Applies to | Scrolling boxes |
| Computed value | Specified keyword or two computed colors |
| Animation type | By computed value type |
| Percentages | Not applicable |
| Related property | scrollbar-width |
| Specification | CSS Scrollbars Styling Module Level 1 |
Valid Values
.container {
scrollbar-color: auto;
}
.container {
scrollbar-color: blue white;
}
.container {
scrollbar-color: #2563eb #f1f5f9;
}
.container {
scrollbar-color: rgb(37 99 235) rgb(241 245 249);
}
.container {
scrollbar-color: hsl(221 83% 53%) hsl(210 40% 96%);
}
.container {
scrollbar-color: currentColor transparent;
}
Invalid Values
.container {
scrollbar-color: blue;
}
.container {
scrollbar-color: blue, white;
}
.container {
scrollbar-color: none;
}
.container {
scrollbar-color: thin;
}
.container {
scrollbar-color: red green blue;
}
.container {
scrollbar-color: 10px 20px;
}
Custom scrollbar colors require exactly two color values separated by whitespace, not commas. The keywords thin and none belong to scrollbar-width, not scrollbar-color.
How It Works
Browsers normally draw scrollbars using colors supplied by the operating system, browser theme, or user preferences. The scrollbar-color property requests custom colors for the scrollbar's main components.
Step 1: Create a Scrollable Element
.scroll-container {
height: 200px;
overflow-y: auto;
}
A scrollbar may appear when the content exceeds the container's available height.
Step 2: Specify the Colors
.scroll-container {
scrollbar-color: #2563eb #e2e8f0;
}
The browser uses blue for the thumb and light gray for the track when it supports the property and permits custom scrollbar colors.
Step 3: Scroll the Content
The scrollbar continues to operate normally. The property changes its colors without modifying scrolling behavior.
Default Behavior
.scroll-container {
scrollbar-color: auto;
}
The browser or operating system selects the scrollbar colors.
Inherited Colors
.wrapper {
scrollbar-color: #2563eb #e2e8f0;
}
Descendant scrolling boxes inherit this value unless they have their own declarations or other cascade rules apply.
No Effect on Scrollbar Dimensions
The property does not change scrollbar width, thickness, placement, or whether a scrollbar is displayed.
Important Consideration
Scrollbar appearance is controlled partly by the browser and operating system. Custom colors may not appear identically across platforms.
Scrollbar Thumb and Track
A scrollbar consists of several visual components. The scrollbar-color property controls the thumb and track colors.
Scrollbar Thumb
The thumb is the movable portion of the scrollbar that represents the visible position within the scrollable content.
.container {
scrollbar-color: #2563eb #e2e8f0;
}
Here, #2563eb is the thumb color.
Scrollbar Track
The track is the area along which the thumb moves.
.container {
scrollbar-color: #2563eb #e2e8f0;
}
Here, #e2e8f0 is the track color.
Color Order
| Position | Component | Example |
|---|---|---|
| First | Scrollbar thumb | #2563eb |
| Second | Scrollbar track | #e2e8f0 |
Reversing the Colors
.container {
scrollbar-color: #e2e8f0 #2563eb;
}
The thumb becomes light gray and the track becomes blue.
Using Similar Colors
.container {
scrollbar-color: #cbd5e1 #e2e8f0;
}
Similar colors create a subtle appearance, but insufficient contrast may make the thumb difficult to identify.
Important Consideration
Choose colors that clearly distinguish the thumb from the track, especially for users who rely on visible scrollbars to navigate content.
Using Different Color Values
The scrollbar-color property accepts standard CSS <color> values.
Named Colors
.container {
scrollbar-color: navy lightgray;
}
Hexadecimal Colors
.container {
scrollbar-color: #2563eb #f1f5f9;
}
RGB Colors
.container {
scrollbar-color: rgb(37 99 235) rgb(241 245 249);
}
HSL Colors
.container {
scrollbar-color: hsl(221 83% 53%) hsl(210 40% 96%);
}
Transparent Colors
.container {
scrollbar-color: rgb(37 99 235 / 80%) transparent;
}
Transparent colors are syntactically valid, but the final appearance depends on how the browser composites and draws the scrollbar.
Using currentColor
.container {
color: #2563eb;
scrollbar-color: currentColor #e2e8f0;
}
The thumb color follows the element's computed color value.
Using CSS Custom Properties
.container {
--scroll-thumb: #2563eb;
--scroll-track: #e2e8f0;
scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}
Custom properties make it easier to maintain consistent scrollbar colors across multiple components.
Important Consideration
Although modern CSS color functions are permitted, actual scrollbar rendering remains subject to browser and operating system behavior.
Styling Scroll Containers
The property is commonly applied to elements that scroll independently of the page.
Vertical Scroll Container
.vertical-panel {
height: 250px;
overflow-y: auto;
scrollbar-color: #2563eb #e2e8f0;
}
The custom colors apply to the panel's scrollbar when one is displayed.
Horizontal Scroll Container
.horizontal-panel {
display: flex;
overflow-x: auto;
scrollbar-color: #16a34a #dcfce7;
}
The same property works for horizontal scrollbars.
Both Scrolling Directions
.scroll-grid {
width: 400px;
height: 250px;
overflow: auto;
scrollbar-color: #7c3aed #ede9fe;
}
When both scrollbars appear, the declaration requests the same thumb and track colors for each direction.
Nested Scroll Containers
.outer-panel {
scrollbar-color: #2563eb #e2e8f0;
}
.inner-panel {
scrollbar-color: #16a34a #dcfce7;
}
The inner panel uses its own colors instead of the inherited value.
Resetting a Nested Scrollbar
.inner-panel {
scrollbar-color: auto;
}
This restores browser-selected scrollbar colors for the inner panel.
Important Consideration
Applying scrollbar-color does not force a scrollbar to appear. Scrollbar visibility still depends on overflow settings, content size, and platform behavior.
Styling the Page Scrollbar
The scrollbar-color property can also customize the scrollbar used for the document viewport.
Viewport Scrollbar
html {
scrollbar-color: #2563eb #e2e8f0;
}
When applied to the document's root element, the property is propagated to the viewport scrollbar.
Dark Page Scrollbar
html {
scrollbar-color: #94a3b8 #0f172a;
}
Default Page Scrollbar
html {
scrollbar-color: auto;
}
Body vs. Root Element
body {
scrollbar-color: #2563eb #e2e8f0;
}
Setting the property on body does not provide the same guaranteed viewport propagation as setting it on the root html element.
Viewport Propagation
For HTML documents, use the html selector when the goal is to style the viewport scrollbar. The root element's scrollbar color value is propagated to the viewport.
Important Consideration
Viewport scrollbars may be hidden automatically or displayed as overlays, depending on the operating system and user preferences.
Combining With scrollbar-width
The scrollbar-color and scrollbar-width properties control different aspects of native scrollbar appearance.
| Property | Purpose |
|---|---|
scrollbar-color |
Specifies scrollbar thumb and track colors. |
scrollbar-width |
Requests the default, thin, or hidden scrollbar thickness. |
Custom Colors With a Thin Scrollbar
.scroll-panel {
scrollbar-color: #2563eb #e2e8f0;
scrollbar-width: thin;
}
The browser requests a thinner scrollbar with custom colors.
Custom Colors With Automatic Width
.scroll-panel {
scrollbar-color: #2563eb #e2e8f0;
scrollbar-width: auto;
}
Hidden Scrollbar
.scroll-panel {
scrollbar-color: #2563eb #e2e8f0;
scrollbar-width: none;
}
When the scrollbar is hidden, its custom colors are not visible. The content may remain scrollable.
Important Consideration
Scrollbar thickness is determined by the browser and operating system. The thin keyword does not specify an exact pixel width.
Browser and System Appearance
Scrollbar styling is affected by browser rendering, operating system settings, and user accessibility preferences.
Traditional Scrollbars
Traditional scrollbars typically reserve visible space alongside scrollable content. Custom thumb and track colors may be readily visible.
Overlay Scrollbars
Overlay scrollbars appear over content and may be hidden until scrolling occurs. Their appearance can differ from traditional scrollbars.
Automatic Scrollbar Hiding
Some operating systems hide scrollbars when they are not actively used. CSS scrollbar colors do not override every system visibility preference.
Forced Colors Mode
When forced-colors: active, the browser computes scrollbar-color as auto so system-selected colors can be used.
Dark Color Schemes
.scroll-panel {
scrollbar-color: #475569 #e2e8f0;
}
@media (prefers-color-scheme: dark) {
.scroll-panel {
scrollbar-color: #94a3b8 #1e293b;
}
}
Different color pairs can be provided for light and dark appearance preferences.
Using color-scheme
.scroll-panel {
color-scheme: dark;
scrollbar-color: auto;
}
With auto, the browser can choose scrollbar colors appropriate for the element's supported color scheme.
Important Consideration
Scrollbar colors are styling preferences rather than guaranteed pixel-perfect results. Test across browsers and operating systems.
Practical Examples
Blue Scrollbar
.scroll-panel {
scrollbar-color: #2563eb #dbeafe;
}
A blue thumb appears against a light blue track.
Green Scrollbar
.scroll-panel {
scrollbar-color: #15803d #dcfce7;
}
A green thumb appears against a pale green track.
Dark Scrollbar
.dark-panel {
background-color: #0f172a;
color: #f8fafc;
scrollbar-color: #94a3b8 #1e293b;
}
Light thumb colors can improve visibility against a dark track.
Using CSS Variables
:root {
--scroll-thumb: #2563eb;
--scroll-track: #e2e8f0;
}
.scroll-panel {
scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}
Custom properties allow scrollbar colors to be reused across the site.
Different Scrollbar Colors
.primary-panel {
scrollbar-color: #2563eb #dbeafe;
}
.secondary-panel {
scrollbar-color: #7c3aed #ede9fe;
}
Separate scroll containers can use different color combinations.
Responsive Color Changes
.scroll-panel {
scrollbar-color: #2563eb #e2e8f0;
}
@media (min-width: 992px) {
.scroll-panel {
scrollbar-color: #7c3aed #ede9fe;
}
}
The scrollbar color pair changes at the specified breakpoint.
Resetting Custom Colors
.scroll-panel {
scrollbar-color: auto;
}
The browser returns to its automatic scrollbar colors.
scrollbar-color Example
This interactive example displays three scrollable panels with different scrollbar colors. Scroll inside each panel to compare the thumb and track appearance.
HTML Example
<div class="scrollbar-color-demo">
<div class="scroll-panel blue">
<h3>Blue Scrollbar</h3>
<p>Scroll to view more content.</p>
<p>The thumb is blue.</p>
<p>The track is light blue.</p>
<p>The scrollbar remains functional.</p>
</div>
<div class="scroll-panel green">
<h3>Green Scrollbar</h3>
<p>Scroll to view more content.</p>
<p>The thumb is green.</p>
<p>The track is pale green.</p>
<p>The scrollbar remains functional.</p>
</div>
<div class="scroll-panel dark">
<h3>Dark Scrollbar</h3>
<p>Scroll to view more content.</p>
<p>The thumb is light gray.</p>
<p>The track is dark gray.</p>
<p>The scrollbar remains functional.</p>
</div>
</div>
CSS Example
.scrollbar-color-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 15px;
}
.scrollbar-color-demo .scroll-panel {
height: 180px;
overflow-y: auto;
padding: 15px;
border: 1px solid #cbd5e1;
}
.scrollbar-color-demo .scroll-panel h3 {
margin-top: 0;
font-size: 1rem;
}
.scrollbar-color-demo .scroll-panel p {
margin-bottom: 35px;
}
.scrollbar-color-demo .blue {
scrollbar-color: #2563eb #dbeafe;
}
.scrollbar-color-demo .green {
scrollbar-color: #15803d #dcfce7;
}
.scrollbar-color-demo .dark {
background-color: #0f172a;
color: #f8fafc;
scrollbar-color: #94a3b8 #1e293b;
}
Each panel requests a different thumb and track color combination. The appearance may vary depending on the browser and operating system.
Changing the Blue Scrollbar
.scrollbar-color-demo .blue {
scrollbar-color: #7c3aed #ede9fe;
}
The blue panel changes to a purple thumb with a pale purple track.
Using a Thin Scrollbar
.scrollbar-color-demo .scroll-panel {
scrollbar-width: thin;
}
The browser requests a thinner scrollbar for all three panels.
Restoring Automatic Colors
.scrollbar-color-demo .scroll-panel {
scrollbar-color: auto;
}
The browser selects the scrollbar colors instead of using the custom pairs.
Browser Compatibility Note
Some browsers or operating systems use overlay scrollbars that are hidden until scrolling. Others may not display custom colors in every situation.
Accessibility Considerations
Scrollbar colors should make scrolling controls easier to identify without interfering with browser or operating system accessibility settings.
Maintain Sufficient Contrast
The scrollbar thumb and track should have a contrast ratio of at least 3:1 where the scrollbar is used as a visual control. This helps users distinguish the movable thumb from its background.
Avoid Similar Colors
.scroll-panel {
scrollbar-color: #d1d5db #e5e7eb;
}
These colors may be difficult to distinguish, particularly for users with reduced vision.
Use Clear Color Differences
.scroll-panel {
scrollbar-color: #1d4ed8 #eff6ff;
}
A darker thumb against a lighter track provides stronger visual separation.
Respect Forced Colors Mode
In forced colors mode, the browser resets the computed scrollbar colors to auto so system colors can be used.
Avoid Hiding Scrollbars Unnecessarily
Visible scrollbars help some users recognize that additional content is available. Avoid hiding them unless another clear scrolling affordance is provided.
Preserve Keyboard Access
Custom scroll containers should remain operable through keyboard navigation.
Do Not Depend on Color Alone
Scrollbar color should not be the only indication that content is scrollable.
Test Different Environments
Check scrollbar visibility and contrast in light mode, dark mode, high contrast settings, and different operating systems.
Common Mistakes
Providing Only One Color
.container {
scrollbar-color: blue;
}
Custom scrollbar styling requires both thumb and track colors.
Using Commas Between Colors
.container {
scrollbar-color: blue, white;
}
Separate the two color values with whitespace, not commas.
Reversing the Color Order
.container {
scrollbar-color: #e2e8f0 #2563eb;
}
The first value always styles the thumb. The second styles the track.
Using scrollbar-width Values
.container {
scrollbar-color: thin;
}
The thin keyword belongs to scrollbar-width.
Expecting Scrollbars to Appear Automatically
The property does not create overflow or force a scrollbar to be displayed.
Applying Colors Only to body
For the document viewport scrollbar, use the root html element.
Using Low-Contrast Colors
Similar thumb and track colors can make the scrollbar difficult to use.
Ignoring Inheritance
The property is inherited. Descendant scroll containers may receive the same colors unless they override the declaration.
Expecting Identical Browser Rendering
Native scrollbar appearance varies across browsers, operating systems, and scrollbar display settings.
Confusing Standard and Vendor-Specific Styling
The standard scrollbar-color property is different from vendor-specific scrollbar pseudo-elements such as ::-webkit-scrollbar-thumb.
Overriding System Accessibility Colors
Do not attempt to defeat forced colors or other user-selected accessibility settings merely to preserve a custom scrollbar appearance.
Important Considerations
Keep the following points in mind when using scrollbar-color:
- It controls the scrollbar thumb and track colors.
- The initial value is
auto. - The property is inherited.
- Custom styling requires exactly two color values.
- The first color styles the thumb.
- The second color styles the track.
- Colors are separated by whitespace, not commas.
- Standard CSS color values can be used.
- CSS custom properties can supply the colors.
- The property works with vertical and horizontal scrollbars.
- It does not change scrollbar thickness or visibility.
- Use
scrollbar-widthto request a different scrollbar thickness. - Use the root
htmlelement to style the viewport scrollbar. - Descendant scroll containers may inherit the colors.
- Native scrollbar appearance depends on browser and operating system behavior.
- Overlay scrollbars may remain hidden until scrolling occurs.
- Forced colors mode resets the computed value to
auto. - Maintain sufficient contrast between the thumb and track.
- Keep scrolling accessible through keyboard and other input methods.
- Use progressive enhancement when custom scrollbar styling is not supported.
Browser Support
The CSS scrollbar-color property is widely available in modern browsers. Support has expanded across Firefox, Chrome, Edge, and Safari.
Although the property is supported in current major browsers, its visual appearance may vary because scrollbars are rendered according to browser and operating system conventions.
For current compatibility information, visit Can I Use? and search for scrollbar-color.
Feature Detection
@supports (scrollbar-color: red blue) {
.scroll-panel {
scrollbar-color: #2563eb #e2e8f0;
}
}
Feature queries allow custom scrollbar colors to be applied when the browser recognizes the property.
Fallback Behavior
When unsupported, the browser uses its normal scrollbar appearance. Scrolling remains functional.
Standard and Vendor-Specific Styling
Some older browser implementations used vendor-specific scrollbar pseudo-elements. The standardized scrollbar-color property provides a simpler way to style thumb and track colors.
When scrollbar-color is set to a value other than auto, supporting browsers may override corresponding ::-webkit-scrollbar-* styling.
Specifications
The scrollbar-color property is defined in the CSS Scrollbars Styling Module Level 1 specification.
CSS Scrollbars Styling Module Level 1
The specification defines how scrollbar thumb and track colors can be customized while preserving native scrolling behavior.
For additional documentation and examples, consult MDN Web Docs.
