A custom scrollbar modifies the default browser scrollbar's appearance to match the website's design and improve overall user experience.
Add the .scrollbar class to a scrollable container to apply the custom scrollbar style.
<div class="scrollbar h-80 overflow-auto">
...
</div>Use the .scrollbar-rounded class with .scrollbar to make the scrollbar rounded.
<div class="scrollbar scrollbar-rounded h-80 overflow-auto">
...
</div>Customize the scrollbar colors by using [&::-webkit-scrollbar-thumb]:bg-{color} for the thumb and [&::-webkit-scrollbar-track]:bg-{color} for the track.
Adjust the scrollbar size using [&::-webkit-scrollbar]:w-* for vertical scrollbar width and [&::-webkit-scrollbar]:h-* for horizontal scrollbar height.
<div class="scrollbar [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:bg-warning [&::-webkit-scrollbar-track]:bg-gray-700 h-80 overflow-auto">
...
</div>By default, scrollbar corners are transparent. Customize them by adding the [&::-webkit-scrollbar-corner]:bg-{color} class to set a background color.
<div class="scrollbar [&::-webkit-scrollbar-corner]:bg-info h-80 overflow-auto">
...
</div>The custom scrollbar component is built using a set of CSS variables. These variables provide flexibility for customizing styles:
.scrollbar {
--scrollbar-size: --spacing(3);
--scrollbar-thumb-color: var(--background-color-emphasis);
--scrollbar-track-color: var(--background-color-muted);
}