scrollbar-width
Baseline 2024Newly available
Since December 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Thescrollbar-width property allows the author to set the desired thickness of an element's scrollbars when they are shown.
The purpose of thescrollbar-width is to optimize the space occupied by the scrollbar on a page or element; the purpose is not related to scrollbar aesthetics. Thescrollbar-width predefined keyword values indicate to the user agent whether a normal or smaller scrollbar should be rendered. Avoid usingnone, as hiding a scrollbar negatively impactsaccessibility.
Note:For elements that are scrollable only via programmatic means and not by direct user interaction, use theoverflow property with a value ofhidden rather thanscrollbar-width: none.
In this article
Syntax
/* Keyword values */scrollbar-width: auto;scrollbar-width: thin;scrollbar-width: none;/* Global values */scrollbar-width: inherit;scrollbar-width: initial;scrollbar-width: revert;scrollbar-width: revert-layer;scrollbar-width: unset;Values
autoThe default scrollbar width for the platform.
thinA thin scrollbar width variant on platforms that provide that option, or a thinner scrollbar than the default platform scrollbar width.
noneNo scrollbar shown, however the element will still be scrollable.
Note:User Agents must apply anyscrollbar-width value set on the root element to the viewport.
Accessibility
Use this property with caution — settingscrollbar-width tothin ornone can make content hard or impossible to scroll if the author does not provide an alternative scrolling mechanism. While swiping gestures or mouse wheels can enable scrolling on such content, some devices have no scroll alternative.
WCAG criterion 2.1.1 (Keyboard) has been in place for a long time to advise on basic keyboard accessibility, and this should include scrolling of content areas. And introduced in WCAG 2.1, criterion 2.5.5 (Target Size) advises that touch targets should be at least 44px in width and height (although the problem is compounded on high-resolution screens; thorough testing is advised).
Formal definition
| Initial value | auto |
|---|---|
| Applies to | scrolling boxes |
| Inherited | no |
| Computed value | as specified |
| Animation type | discrete |
Formal syntax
scrollbar-width =
auto|
thin|
none
Examples
>Sizing overflow scrollbars
CSS
.scroller { width: 300px; height: 100px; overflow-y: scroll; scrollbar-width: thin;}HTML
<div> Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</div>Result
Specifications
| Specification |
|---|
| CSS Scrollbars Styling Module Level 1> # scrollbar-width> |
Browser compatibility
Loading…