CSS Scrollbars — Custom Styling Guide
Custom scrollbars let you match the scrollbar look to your site’s design system instead of relying on the operating system’s default.
What You’ll Learn
By the end, you’ll style scrollbars in WebKit browsers (Chrome, Safari, Edge) using ::-webkit-scrollbar pseudo-elements, use Firefox’s scrollbar-width and scrollbar-color properties, create thin custom scrollbars, and ensure sufficient contrast for accessibility.
Where This Fits
flowchart LR
A["CSS Styling"] --> B["**CSS Scrollbars**"]
B --> C["CSS Reference"]
C --> D["Frontend-Ready Developer"]
style B fill:#f97316,stroke:#c2410c,color:#fff
style A fill:#e5e7eb,stroke:#9ca3af,color:#374151
style D fill:#22c55e,stroke:#16a34a,color:#fff
WebKit Browsers (Chrome, Safari, Edge)
WebKit browsers use vendor-prefixed pseudo-elements:
/* Scrollbar width */
::-webkit-scrollbar {
width: 8px; /* Vertical scrollbar width */
height: 8px; /* Horizontal scrollbar height */
}
/* Track (the background) */
::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 4px;
}
/* Thumb (the draggable handle) */
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
/* Thumb on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Corner (where horizontal and vertical scrollbars meet) */
::-webkit-scrollbar-corner {
background: #f1f1f1;
}Full Pseudo-Element Reference
| Pseudo-element | What It Styles |
|---|---|
::-webkit-scrollbar | The entire scrollbar (width/height) |
::-webkit-scrollbar-track | The track background |
::-webkit-scrollbar-thumb | The draggable handle |
::-webkit-scrollbar-thumb:hover | Thumb on hover |
::-webkit-scrollbar-button | Arrows at the ends |
::-webkit-scrollbar-corner | The corner intersection |
Note: -webkit-scrollbar-button is rarely styled — most designs hide the arrow buttons for a cleaner look.
Firefox
Firefox uses two simple properties instead of pseudo-elements:
/* Make scrollbar thin and color it */
.element {
scrollbar-width: thin; /* auto | thin | none */
scrollbar-color: #888 #f1f1f1; /* thumb color track color */
}
/* Apply globally */
html {
scrollbar-width: thin;
scrollbar-color: #888 #f1f1f1;
}| Firefox Property | Values |
|---|---|
scrollbar-width | auto (default), thin, none |
scrollbar-color | <thumb-color> <track-color> |
Cross-Browser Pattern
Since WebKit uses pseudo-elements and Firefox uses properties, you need both:
/* Firefox */
html {
scrollbar-width: thin;
scrollbar-color: #888 #f1f1f1;
}
/* WebKit */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 4px;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}Themed Scrollbar Examples
Light Theme
html {
scrollbar-width: thin;
scrollbar-color: #cbd5e0 #f8fafc;
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #f8fafc; }
::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }Dark Theme
html {
scrollbar-width: thin;
scrollbar-color: #475569 #1e293b;
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #1e293b; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }Brand-Colored
html {
scrollbar-width: thin;
scrollbar-color: #3498db #e2e8f0;
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #e2e8f0; }
::-webkit-scrollbar-thumb { background: #3498db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2980b9; }Common Scrollbar Mistakes
1. Making Scrollbars Too Thin or Invisible
/* ❌ Users can't find the scrollbar */
::-webkit-scrollbar { width: 2px; }
html { scrollbar-width: none; }A scrollbar that’s too thin or hidden makes it hard for users to know where they are on a page. If you make it thin (4-6px), ensure it has enough contrast.
2. Low Contrast Thumb
/* ❌ Thumb blends into the track */
::-webkit-scrollbar-thumb { background: #f1f1f1; }
::-webkit-scrollbar-track { background: #f1f1f1; }Ensure the thumb has sufficient contrast against the track for accessibility.
3. Forgetting Hover State
/* ❌ Thumb doesn't change on hover — poor UX */
::-webkit-scrollbar-thumb { background: #ccc; }
/* ✅ Indicate interactivity */
::-webkit-scrollbar-thumb { background: #ccc; }
::-webkit-scrollbar-thumb:hover { background: #999; }4. Using overflow: hidden to Hide Scrollbars
/* ❌ Breaks scrolling entirely */
.element { overflow: hidden; }
/* ✅ Better: only hide the scrollbar style, keep scrolling */Instead of disabling overflow, use scrollbar-width: thin or just style them to look minimal.
Security Angle — Consistent UI
Custom scrollbars in Doda Browser use the brand’s color scheme, providing a consistent and polished visual experience that reinforces the product identity — similar design consistency applies in Durga Antivirus Pro dashboards.
Try It Yourself
Common Mistakes Beginners Make
1. Skipping the Fundamentals
Many beginners jump straight to advanced topics without mastering the basics. Take time to understand the core concepts before moving on.
2. Not Practicing Enough
Reading tutorials without writing code leads to shallow understanding. Code along with every example and experiment on your own.
3. Ignoring Error Messages
Error messages tell you exactly what went wrong. Read them carefully — they usually point to the line and type of issue.
4. Copy-Pasting Without Understanding
It’s tempting to copy code from tutorials, but typing it yourself and understanding each line builds real skill.
5. Giving Up Too Early
Every developer hits frustrating bugs. Take breaks, ask for help, and remember that struggling is part of learning.
Practice Questions
Q1: How do you style the scrollbar in Chrome/Safari? Use ::-webkit-scrollbar pseudo-elements. Style the track with ::-webkit-scrollbar-track and the thumb with ::-webkit-scrollbar-thumb.
Q2: How do you style the scrollbar in Firefox? Use scrollbar-width: thin and scrollbar-color: <thumb> <track> on the element. No pseudo-elements needed.
Q3: Why should you avoid making scrollbars invisible? Users need to see where they are on a page. Invisible or extremely thin scrollbars harm usability and accessibility.
Q4: What does Hides the scrollbar entirely while still allowing scrolling. Use with caution — it can confuse users who don’t see a scrollbar.scrollbar-width: none do in Firefox?
Q5: How do you style scrollbar corners in WebKit? Use ::-webkit-scrollbar-corner — it styles the square where horizontal and vertical scrollbars intersect.
FAQ
Can I style scrollbars in all browsers?
WebKit browsers (Chrome, Safari, Edge) support ::-webkit-scrollbar pseudo-elements. Firefox supports scrollbar-width and scrollbar-color. There’s no universal standard yet.
Is custom scrollbar styling accessible?
Yes, if you maintain sufficient contrast between the thumb and track, and keep the scrollbar wide enough (at least 6-8px) to grab.
How do I hide the scrollbar but keep scrolling?
In Firefox: scrollbar-width: none. In WebKit: ::-webkit-scrollbar { display: none; }. But think carefully before hiding it.
Does ::-webkit-scrollbar work on mobile?
No. Mobile browsers don’t display traditional scrollbars — touch scrolling uses swipe gestures and hides scrollbars by default.
FAQ
{< faq >}
- What is Css Scrollbars?
- Css Scrollbars refers to the core concepts and practices used to build and manage modern web applications. Understanding it is essential for web developers.
- Do I need prior experience to learn Css Scrollbars?
- Basic familiarity with web development concepts helps, but Css Scrollbars can be learned step by step even as a beginner.
- How long does it take to learn Css Scrollbars?
- With consistent practice, you can grasp the fundamentals in a few days to a week. Mastery takes ongoing practice and real-world projects.
- Where can I use Css Scrollbars in real projects?
- Css Scrollbars is used in a wide range of applications — from simple websites to complex enterprise systems, depending on the specific tools and technologies involved.
- What are common tools used with Css Scrollbars?
- The specific tools depend on the technology stack, but version control (Git), package managers, and testing frameworks are commonly used alongside most development topics.
{< /faq >}
FAQ
What’s Next?
Continue with more CSS topics:
What’s Next
Congratulations on completing this Css Scrollbars tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro