Scroll Area
A native scroll container with custom scrollbars.
View as MarkdownAnatomy
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
Groups all parts of the scroll area.
Renders a <div> element.
overflowEdgeThresholdUnion0
Union- Description
The threshold in pixels that must be passed before the overflow edge attributes are applied. Accepts a single number for all edges or an object to configure them individually.
- Type
| number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }> | undefined- Default
0
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ScrollArea.Root.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Root.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Root.State, ) => ReactElement) | undefined
data-has-overflow-x
data-has-overflow-y
data-overflow-x-end
data-overflow-x-start
data-overflow-y-end
data-overflow-y-start
data-scrolling
--scroll-area-corner-height
The scroll area’s corner height.
--scroll-area-corner-width
The scroll area’s corner width.
Additional Types
ScrollArea.Root.Props
Re-Export of Root props as ScrollAreaRootProps
ScrollArea.Root.State
type ScrollAreaRootState = {
scrolling: boolean;
hasOverflowX: boolean;
hasOverflowY: boolean;
overflowXStart: boolean;
overflowXEnd: boolean;
overflowYStart: boolean;
overflowYEnd: boolean;
cornerHidden: boolean;
};Viewport
The actual scrollable container of the scroll area.
Renders a <div> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ScrollArea.Viewport.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Viewport.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Viewport.State, ) => ReactElement) | undefined
data-has-overflow-x
data-has-overflow-y
data-overflow-x-end
data-overflow-x-start
data-overflow-y-end
data-overflow-y-start
data-scrolling
--scroll-area-overflow-x-end
The distance from the horizontal end edge in pixels.
--scroll-area-overflow-x-start
The distance from the horizontal start edge in pixels.
--scroll-area-overflow-y-end
The distance from the vertical end edge in pixels.
--scroll-area-overflow-y-start
The distance from the vertical start edge in pixels.
Additional Types
ScrollArea.Viewport.Props
Re-Export of Viewport props as ScrollAreaViewportProps
ScrollArea.Viewport.State
type ScrollAreaViewportState = {
scrolling: boolean;
hasOverflowX: boolean;
hasOverflowY: boolean;
overflowXStart: boolean;
overflowXEnd: boolean;
overflowYStart: boolean;
overflowYEnd: boolean;
cornerHidden: boolean;
};Content
A container for the content of the scroll area.
Renders a <div> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ScrollArea.Content.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Content.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Content.State, ) => ReactElement) | undefined
Additional Types
ScrollArea.Content.Props
Re-Export of Content props as ScrollAreaContentProps
ScrollArea.Content.State
type ScrollAreaContentState = {
scrolling: boolean;
hasOverflowX: boolean;
hasOverflowY: boolean;
overflowXStart: boolean;
overflowXEnd: boolean;
overflowYStart: boolean;
overflowYEnd: boolean;
cornerHidden: boolean;
};Scrollbar
A vertical or horizontal scrollbar for the scroll area.
Renders a <div> element.
orientation'vertical' | 'horizontal''vertical'
'vertical' | 'horizontal'- Name
- Description
Whether the scrollbar controls vertical or horizontal scroll.
- Type
'vertical' | 'horizontal' | undefined- Default
'vertical'
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ScrollArea.Scrollbar.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Scrollbar.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
boolean- Name
- Description
Whether to keep the HTML element in the DOM when the viewport isn’t scrollable.
- Type
boolean | undefined- Default
false
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Scrollbar.State, ) => ReactElement) | undefined
data-orientation
data-has-overflow-x
data-has-overflow-y
data-hovering
data-overflow-x-end
data-overflow-x-start
data-overflow-y-end
data-overflow-y-start
data-scrolling
--scroll-area-thumb-height
The scroll area thumb’s height.
--scroll-area-thumb-width
The scroll area thumb’s width.
Additional Types
ScrollArea.Scrollbar.Props
Re-Export of Scrollbar props as ScrollAreaScrollbarProps
ScrollArea.Scrollbar.State
type ScrollAreaScrollbarState = {
hovering: boolean;
scrolling: boolean;
orientation: 'vertical' | 'horizontal';
hasOverflowX: boolean;
hasOverflowY: boolean;
overflowXStart: boolean;
overflowXEnd: boolean;
overflowYStart: boolean;
overflowYEnd: boolean;
cornerHidden: boolean;
};Thumb
The draggable part of the scrollbar that indicates the current scroll position.
Renders a <div> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ScrollArea.Thumb.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Thumb.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Thumb.State, ) => ReactElement) | undefined
data-orientation
Additional Types
ScrollArea.Thumb.Props
Re-Export of Thumb props as ScrollAreaThumbProps
ScrollArea.Thumb.State
type ScrollAreaThumbState = { orientation?: 'horizontal' | 'vertical' };Corner
A small rectangular area that appears at the intersection of horizontal and vertical scrollbars.
Renders a <div> element.
classNamestring | function—
string | function- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ScrollArea.Corner.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: ScrollArea.Corner.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
ReactElement | function- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ScrollArea.Corner.State, ) => ReactElement) | undefined
Additional Types
ScrollArea.Corner.Props
Re-Export of Corner props as ScrollAreaCornerProps
ScrollArea.Corner.State
type ScrollAreaCornerState = {};