How do I style scrollbars with CSS to match my site theme?
Asked on Sep 19, 2025
Answer
To style scrollbars with CSS and match them to your site theme, you can use the `::-webkit-scrollbar` pseudo-elements for WebKit browsers and the `scrollbar-color` and `scrollbar-width` properties for Firefox. This allows you to customize the appearance of the scrollbar to better fit your design.
<!-- BEGIN COPY / PASTE -->
/* For WebKit browsers */
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background-color: #888;
border-radius: 6px;
border: 3px solid #f1f1f1;
}
/* For Firefox */
body {
scrollbar-width: thin;
scrollbar-color: #888 #f1f1f1;
}
<!-- END COPY / PASTE -->Additional Comment:
- WebKit browsers include Chrome, Safari, and Edge, which support the `::-webkit-scrollbar` pseudo-elements.
- Firefox uses `scrollbar-color` and `scrollbar-width` to style scrollbars, which are applied to the entire document or specific elements.
- Ensure contrast between the scrollbar thumb and track for accessibility.
- Test your scrollbar styles across different browsers to ensure compatibility.
Recommended Links: