Scroll Area
A custom scrollable area component with styled scrollbars.
Anatomy
<ScrollArea.Root>
<ScrollArea.Viewport>
<ScrollArea.Content />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar>
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>
Required style
Add these styles to ScrollArea.Viewport to hide the native scrollbar:
[data-scroll-area-viewport] {
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
Examples
Basic
A scrollable area with a custom scrollbar.
Horizontal
Scroll horizontally only.
Both Directions
Scroll horizontally and vertically.
Nested
Nest scroll areas for complex layouts.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
ids | ElementIdsThe ids of the scroll area elements | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-root] | <uid> |
[data-overflow-x] | Present when the content overflows the x-axis |
[data-overflow-y] | Present when the content overflows the y-axis |
| CSS Variable | Description |
|---|---|
--corner-width | The width of the Root |
--corner-height | The height of the Root |
--thumb-width | The width of the slider thumb |
--thumb-height | The height of the slider thumb |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-content] | <uid> |
[data-overflow-x] | Present when the content overflows the x-axis |
[data-overflow-y] | Present when the content overflows the y-axis |
Corner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ScrollAreaCornerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-corner] | <uid> |
[data-hover] | Present when hovered |
[data-state] | "hidden" | "visible" |
[data-overflow-x] | Present when the content overflows the x-axis |
[data-overflow-y] | Present when the content overflows the y-axis |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseScrollAreaReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Scrollbar
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
orientation | Orientation | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ScrollAreaScrollbarState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-scrollbar] | <uid> |
[data-orientation] | The orientation of the scrollbar |
[data-scrolling] | Present when scrolling |
[data-hover] | Present when hovered |
[data-dragging] | Present when in the dragging state |
[data-overflow-x] | Present when the content overflows the x-axis |
[data-overflow-y] | Present when the content overflows the y-axis |
Thumb
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-thumb] | <uid> |
[data-orientation] | The orientation of the thumb |
[data-hover] | Present when hovered |
[data-dragging] | Present when in the dragging state |
Viewport
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-scroll-area-viewport] | <uid> |
[data-at-top] | Present when scrolled to the top edge |
[data-at-bottom] | Present when scrolled to the bottom edge |
[data-at-left] | Present when scrolled to the left edge |
[data-at-right] | Present when scrolled to the right edge |
[data-overflow-x] | Present when the content overflows the x-axis |
[data-overflow-y] | Present when the content overflows the y-axis |
| CSS Variable | Description |
|---|---|
--scroll-area-overflow-x-start | The distance from the horizontal start edge in pixels |
--scroll-area-overflow-x-end | The distance from the horizontal end edge in pixels |
--scroll-area-overflow-y-start | The distance from the vertical start edge in pixels |
--scroll-area-overflow-y-end | The distance from the vertical end edge in pixels |
Context
API
| Property | Type |
|---|---|
isAtTop | booleanWhether the scroll area is at the top |
isAtBottom | booleanWhether the scroll area is at the bottom |
isAtLeft | booleanWhether the scroll area is at the left |
isAtRight | booleanWhether the scroll area is at the right |
hasOverflowX | booleanWhether the scroll area has horizontal overflow |
hasOverflowY | booleanWhether the scroll area has vertical overflow |
getScrollProgress | () => PointGet the scroll progress as values between 0 and 1 |
scrollToEdge | (details: ScrollToEdgeDetails) => voidScroll to the edge of the scroll area |
scrollTo | (details: ScrollToDetails) => voidScroll to specific coordinates |
getScrollbarState | (props: ScrollbarProps) => ScrollbarStateReturns the state of the scrollbar |
getRootState | () => RootStateReturns the state of the root. The content shares it. |
getViewportState | () => ViewportStateReturns the state of the viewport |
getCornerState | () => CornerStateReturns the state of the corner |