scrollbar-width
Example
.carousel {
scrollbar-width: 4px;
}.carousel {
scrollbar-width: thin;
}scrollbar-width only accepts 'auto', 'thin' or 'none'; a pixel length is invalid and the declaration is ignored.
Common mistakes
- Setting a pixel value like '8px', which is invalid and ignored.
- Hiding the scrollbar so users don't notice the area can scroll.
Key points
- Values are the keywords 'auto', 'thin' or 'none', not pixel lengths.
- 'none' is used only where content can still be scrolled with keyboard, touch or visible controls.
- Scrollbars are hidden with
scrollbar-width: none, not only with::-webkit-scrollbar { display: none }.
Interview questions
How do I hide the scrollbar but keep scrolling?
Set scrollbar-width: none on the scroll container. The content still scrolls with wheel, touch and keyboard.
Can I set an exact scrollbar width in pixels?
No. The standard property only takes keywords; the exact size of 'thin' is chosen by the browser.
Is scrollbar-width inherited?
No. Set it on each scroll container whose scrollbar you want to change.