Web · Components
ScrollArea
Scrollable area.
Live example
Preview
On devices with a mouse the bar sits over the content and only appears while scrolling or when the pointer nears the edge; it takes no width. On touch screens the browser's bar is used. The page's own bar looks the same (UIProvider).
Code
Events
- Events appear here when you interact with the preview.
Import
Scrollable area. Instead of the classic scrollbar on Windows and Linux, it draws a thin bar that sits over the content and appears only while scrolling or when the pointer reaches the edge; like on mobile and macOS it takes no width. Scrolling itself is native (wheel, touchpad, keyboard, find in page, scroll links); the bar can be dragged and clicking the track scrolls one page.
The same bar is drawn on touch screens (appears when scrolling with a finger, the thumb can be dragged). In Windows high contrast mode the browser's native bar is used. To go back to the native bar across the app, <UIProvider scrollbar="native">.
Give the height to the area itself (h-64, max-h-96, flex-1…); for content classes like padding use viewportClassName.
You don't need to do anything for the page's own bar; UIProvider sets it up. Dialog, Sheet and Table also use this bar in their scroll areas.
Examples
Scroll direction.
ScrollAreaProps
interfaceProps of the ScrollArea component.
Extends: ComponentProps<"div">
| Name | Type | Default | Description |
|---|---|---|---|
orientation? | ScrollOrientation | "vertical" | Which direction to scroll. |
label? | string | Screen reader name of the area. If given, the area can be focused with the keyboard and scrolled with arrow keys (recommended if there is no focusable element inside). | |
viewportClassName? | string | Classes of the element that holds the content and actually scrolls (e.g. padding). | |
viewportRef? | Ref<HTMLDivElement> | Ref of the element that actually scrolls (e.g. to call scrollTo). |