ScrollArea
Scroll native content with styled or native scrollbars and edge shadows.
Anatomy#
Usage#
Use ScrollArea to constrain overflowing content. Scrolling stays native: wheel, touch, keyboard, and scroll anchoring behave as in any scroll container.
By default ScrollArea hides the native scrollbar and draws its own over the content; set
scrollbarMode="native" to keep the browser’s. When the area is a landmark of its own, label it
with role="region" and aria-label.
Structure and sizing#
Set a height or maximum height on the root for vertical scrolling and a width for horizontal
scrolling. The root positions the scrollbars; the viewport scrolls; the content wraps the
children. Put content layout such as flex and gap on classes.content, not on the root.
class, style, ref, and other attributes such as role and aria-label go to the root.
onScroll and tabIndex go to the viewport, and viewportRef receives it. The viewport joins
the tab order while its content overflows and leaves it when the content fits; pass tabIndex to
override this.
Orientation#
orientation selects the scrollable axes: vertical (default), horizontal, or both. With
both, the two scrollbars meet at the corner. Horizontal and two-axis content grows to its
natural width.
Scrollbars#
scrollbarMode selects how scrollbars appear:
| Value | Behavior |
|---|---|
hover |
Custom scrollbars while the pointer is over the area or it scrolls. Default. |
always |
Custom scrollbars at all times while an axis overflows. |
scroll |
Custom scrollbars while the area scrolls. |
native |
Browser scrollbars, unhidden; no custom track or corner is drawn. |
hidden |
No scrollbars; wheel, touch, and keyboard scrolling still work. |
Custom scrollbars only appear on an axis whose content overflows. Set scrollbarWidth="thin" for
thinner custom scrollbars; with native it applies scrollbar-width: thin.
hover and scroll scrollbars stay visible for scrollHideDelay milliseconds (default 600)
after activity ends. Drag the thumb to scroll, or press the track to jump to that position.
Scrollbars are hidden from assistive technology; keyboard scrolling goes through the focusable
viewport.
Edge shadows#
Set fade to fade content out at edges that have more content beyond them. The shadow grows with
the remaining distance up to fadeSize pixels (default 40), so it appears gradually instead of
switching on. The mask fades content into the background behind the container.
Overflow state#
onOverflowChange receives { x: { start, end }, y: { start, end } } whenever the edges with
more content beyond them change. start and end are logical: in RTL content, the x start
edge is on the right.
scrollThreshold sets how close to an edge, in pixels, scrolling counts as reaching it. It applies
to onOverflowChange, the data-overflow-*-start and -end attributes, and the on*Reached
callbacks, not to the shadow mask.
onTopReached, onBottomReached, onLeftReached, and onRightReached fire once each time scrolling
reaches a physical edge (within scrollThreshold) of an overflowing axis. In RTL content,
onLeftReached and onRightReached follow the physical edges, not the logical start/end. They
do not fire for the initial position; combine onBottomReached with scrollThreshold to load more
content before the end.
To scroll programmatically, take the viewport from viewportRef and call scrollTo on it.
Data attributes and CSS variables#
The root and scrollbar slots expose state attributes for custom styling:
- Root:
data-orientation,data-overflow-xanddata-overflow-ywhile an axis overflows,data-overflow-{x,y}-{start,end}for each overflowing edge,data-scrolling, anddata-hovering. - Scrollbar:
data-orientation,data-visible,data-dragging, anddata-cornerwhile the corner is shown. - Corner:
data-visible.
The root also exposes the remaining scroll distance of each edge in pixels as
--scroll-area-overflow-x-start, --scroll-area-overflow-x-end,
--scroll-area-overflow-y-start, and --scroll-area-overflow-y-end. Use them for custom
edge effects.
Theme overrides#
Set scrollArea.defaultVariants to choose the scrollbar mode or enable shadows across a provider;
scrollbarMode: 'native' restores browser scrollbars everywhere. The recipe exposes
--scroll-area-shadow-size and the mask layers --scroll-area-shadow-y and
--scroll-area-shadow-x.
The shadow size resolves in this order, highest first: root style, styles.root, an explicit
fadeSize, then recipe and Theme defaults.
Examples#
Edge shadows#
Enable fade to indicate clipped content along overflowing edges.
Horizontal#
Set orientation="horizontal" for horizontal scrolling.
RTL#
Set dir="rtl" and the scrollbar moves to the left edge. Horizontal content scrolls from the right
edge, and the thumb and shadows follow the logical edges.
Scrollbar width#
scrollbarWidth="thin" draws thinner custom scrollbars, or applies scrollbar-width: thin with
scrollbarMode="native".
Both axes#
Set orientation="both" for content that overflows in both directions.
Overflow state#
Use onOverflowChange to detect hidden overflow and viewportRef to scroll programmatically.
Infinite scroll#
onBottomReached with scrollThreshold requests the next page shortly before the end.
API Reference#
Attributes#
data-hoveringdata-orientationdata-overflow-xdata-overflow-x-enddata-overflow-x-startdata-overflow-ydata-overflow-y-enddata-overflow-y-startdata-scrollingdata-cornerdata-draggingdata-visibleProps#
Props for the ScrollArea component. Renders a <div> element by default.