Scroll Area
A high-quality, unstyled React scroll area that provides a native scroll container with custom scrollbars.
A native scroll container with custom scrollbars.
Anatomy
Import the component and assemble its parts:
import { ScrollArea } from '@base-ui/react/scroll-area';
<ScrollArea.Root>
<ScrollArea.Viewport>
<ScrollArea.Content />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar>
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>;Examples
Both scrollbars
Use <ScrollArea.Corner> to prevent the scrollbars from intersecting.
Gradient scroll fade
Use the viewport overflow CSS variables to fade the scroll edges, which gradually increases in strength as the user scrolls away from the edges.
The CSS variables do not inherit by default to improve rendering performance in complex scroll areas with deep subtrees. To use them in child elements (or pseudo-elements on <ScrollArea.Viewport>), you must manually set each variable to inherit.
.Viewport {
&::before,
&::after {
content: '';
display: block;
left: 0;
width: 100%;
position: absolute;
pointer-events: none;
border-radius: 0.375rem;
transition: height 0.1s ease-out;
}
&::before {
--scroll-area-overflow-y-start: inherit;
top: 0;
height: min(40px, var(--scroll-area-overflow-y-start));
background: linear-gradient(to bottom, var(--color-gray-50), transparent);
}
&::after {
--scroll-area-overflow-y-end: inherit;
bottom: 0;
height: min(40px, var(--scroll-area-overflow-y-end, 40px));
background: linear-gradient(to top, var(--color-gray-50), transparent);
}
}For SSR, a fallback can be used as part of the var() function to provide a default height.
.Viewport::after {
height: min(40px, var(--scroll-area-overflow-y-end, 40px));
}API reference
Root
| Name | Type | Default | Description |
|---|---|---|---|
xStartRequired | number | — | — |
xEndRequired | number | — | — |
yStartRequired | number | — | — |
yEndRequired | number | — | — |
Scrollbar
| Name | Type | Default | Description |
|---|---|---|---|
orientationOptional | 'vertical' | 'horizontal' | undefined | vertical | Whether the scrollbar controls vertical or horizontal scroll. |
keepMountedOptional | boolean | undefined | false | Whether to keep the HTML element in the DOM when the viewport isn't scrollable. |