Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a custom scrollbar using only CSS?
Asked on Apr 22, 2026
Answer
Creating a custom scrollbar using only CSS involves styling the scrollbar pseudo-elements. This allows you to change the appearance of the scrollbar track and thumb. Here's a basic example to get you started.
<!-- BEGIN COPY / PASTE -->
<style>
/* For WebKit browsers */
::-webkit-scrollbar {
width: 12px; /* Width of the scrollbar */
}
::-webkit-scrollbar-track {
background: #f1f1f1; /* Color of the track */
}
::-webkit-scrollbar-thumb {
background: #888; /* Color of the thumb */
border-radius: 6px; /* Rounded corners */
}
::-webkit-scrollbar-thumb:hover {
background: #555; /* Color of the thumb on hover */
}
</style>
<div style="height: 200px; overflow-y: scroll;">
<!-- Content here will have a custom scrollbar -->
<p>Sample content to scroll...</p>
<p>Sample content to scroll...</p>
<p>Sample content to scroll...</p>
<p>Sample content to scroll...</p>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- This example uses WebKit-specific pseudo-elements, which work in browsers like Chrome and Safari.
- Other browsers, like Firefox, require different approaches such as the scrollbar-width and scrollbar-color properties.
- Custom scrollbars can enhance user experience but ensure they remain functional and accessible.
Recommended Links:
