Skip to main content

How to Create Custom Scrollbar in CSS

Learn to style scrollbars with CSS using webkit pseudo-elements and Firefox properties. Cross-browser examples included.

Why Style Your Scrollbars?

Custom scrollbars can significantly improve your website's visual consistency and user experience. Here's what you can customize:

  • Width and size - Make scrollbars thin, thick, or completely hidden
  • Colors - Match your brand colors for the track and thumb
  • Border radius - Create rounded, pill-shaped scrollbars
  • Hover states - Add interactive feedback on hover

Live demo - scroll inside:

Item 1

Scroll to see the custom scrollbar in action

Item 2

Scroll to see the custom scrollbar in action

Item 3

Scroll to see the custom scrollbar in action

Item 4

Scroll to see the custom scrollbar in action

Item 5

Scroll to see the custom scrollbar in action

Item 6

Scroll to see the custom scrollbar in action

Item 7

Scroll to see the custom scrollbar in action

Item 8

Scroll to see the custom scrollbar in action

Item 9

Scroll to see the custom scrollbar in action

Item 10

Scroll to see the custom scrollbar in action

Step-by-Step Tutorial

Follow these steps to create a custom scrollbar. Click any code block to copy.

1

Target the Scrollbar

Use the ::-webkit-scrollbar pseudo-element to target the entire scrollbar. Set the width for vertical scrollbars and height for horizontal ones.

2

Style the Track

The track is the background area where the thumb moves. Style it with ::-webkit-scrollbar-track.

3

Style the Thumb

The thumb is the draggable handle. Use ::-webkit-scrollbar-thumb and add hover states for interactivity.

4

Add Firefox Support

Firefox uses standard CSS properties: scrollbar-width and scrollbar-color. Limited customization compared to WebKit.

Complete Cross-Browser Code

Here's the complete CSS for a custom scrollbar that works in all modern browsers:

Scrollbar Style Examples

Click any style to copy the CSS. Each example includes both WebKit and Firefox support.

Hide Scrollbar (Keep Scrolling)

Sometimes you want to hide the scrollbar but keep the content scrollable:

Accessibility note: Hidden scrollbars can confuse users who rely on them for navigation. Consider adding visual cues that content is scrollable.

Browser Support

PropertyChromeSafariFirefoxEdge
::-webkit-scrollbarYesYesNoYes
scrollbar-width121+No64+121+
scrollbar-color121+No64+121+

For full cross-browser support, include both WebKit pseudo-elements and standard scrollbar properties.

Frequently Asked Questions

Can I style scrollbars in all browsers?

WebKit browsers (Chrome, Safari, Edge) support extensive customization via ::-webkit-scrollbar pseudo-elements. Firefox supports scrollbar-width and scrollbar-color properties for basic styling. Internet Explorer/Edge legacy support -ms-overflow-style for hiding scrollbars only.

How do I hide a scrollbar but keep scrolling?

Use ::-webkit-scrollbar { display: none; } for WebKit browsers and scrollbar-width: none; for Firefox. Add -ms-overflow-style: none; for older Edge/IE. The element will still be scrollable.

What's the difference between scrollbar track and thumb?

The track is the background/gutter where the scrollbar moves. The thumb is the draggable handle that users interact with to scroll. In CSS, style them with ::-webkit-scrollbar-track and ::-webkit-scrollbar-thumb respectively.

Why isn't my custom scrollbar showing?

Make sure your element has overflow: auto or overflow: scroll set. The ::-webkit-scrollbar pseudo-elements only work when content overflows. Also ensure you've set a width for vertical scrollbars or height for horizontal ones.

Are custom scrollbars bad for accessibility?

Custom scrollbars can be problematic if they're too thin or have poor contrast. Keep scrollbars at least 8-10px wide, ensure good color contrast between thumb and track, and consider adding hover states for better visibility.