Introducing PrimeReact v11-alpha 🎉Discover Now

ScrollArea

An unstyled, accessible scroll area component with custom scrollbar support.

Build fully custom scrollable regions with complete control over scrollbar design and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use ScrollArea with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with six sub-components: Root, Viewport, Content, Scrollbar, Thumb, Corner
  • Automatic thumb sizing based on viewport-to-content ratio
  • Pointer-based drag interaction on both scrollbar track and thumb
  • ResizeObserver for automatic recalculation on content changes
  • Variant-based scrollbar visibility control (auto, hover, scroll, always, hidden)
  • Scroll edge detection for fade effects and loading indicators

Usage#

import { ScrollArea } from 'primereact/scrollarea';
<ScrollArea.Root>
    <ScrollArea.Viewport>
        <ScrollArea.Content></ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar>
        <ScrollArea.Thumb />
    </ScrollArea.Scrollbar>
</ScrollArea.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<ScrollArea.Root as="section">
    <ScrollArea.Viewport as="main">
        <ScrollArea.Content as="article"></ScrollArea.Content>
    </ScrollArea.Viewport>
</ScrollArea.Root>

Render Function Children#

Sub-components accept a render function as children, providing access to the component instance.

<ScrollArea.Root>{(instance) => <div>{instance.state.scrolling ? 'Scrolling...' : 'Idle'}</div>}</ScrollArea.Root>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

ScrollAreaRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaRootInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
stepnumber5
Step factor to scroll the content while pressing the arrow keys.
variant"hidden" | "auto" | "always" | "scroll" | "hover"'auto'
Controls scrollbar visibility behavior. - `auto` : visible on hover or while scrolling - `hover` : visible on hover - `scroll` : visible while scrolling - `always` : always visible - `hidden` : never visible but still scrollable
maskbooleanfalse
When enabled, a mask is added to the scrollable content to provide a visual indication of overflow.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"scrollarea"
data-part"root"
data-variantCurrent variant value
data-scrollingPresent when actively scrolling
data-has-overflow-xPresent when content overflows horizontal
data-has-overflow-yPresent when content overflows vertical
data-scroll-x-beforePresent when scrolled past left edge
data-scroll-x-afterPresent when content remains to the right
data-scroll-y-beforePresent when scrolled past top edge
data-scroll-y-afterPresent when content remains below

CSS Custom Properties

The Root element sets CSS custom properties on its style for scrollbar corner sizing.

CSS VariableDescription
--corner-heightHeight of the scrollbar corner in pixels
--corner-widthWidth of the scrollbar corner in pixels

Defines passthrough(pt) options of ScrollArea component.

labeltypedescription
rootScrollAreaRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
viewportScrollAreaRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the viewport's DOM element.
scrollbarScrollAreaRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the scrollbar's DOM element.
thumbScrollAreaRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the thumb's DOM element.
cornerScrollAreaRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the corner's DOM element.

ScrollAreaViewport#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaViewportInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaViewportInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaViewportInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaViewportPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaViewportInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"scrollarea"
data-part"viewport"

Defines passthrough(pt) options of ScrollAreaViewport component.

labeltypedescription
rootScrollAreaViewportPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

ScrollAreaContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaContentInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ScrollAreaContent component.

labeltypedescription
rootScrollAreaContentPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

ScrollAreaScrollbar#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaScrollbarInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaScrollbarInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaScrollbarInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaScrollbarPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaScrollbarInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
orientation"horizontal" | "vertical"'vertical'
The orientation of the scrollbar.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"scrollarea"
data-part"scrollbar-y" or "scrollbar-x"

CSS Custom Properties

The Scrollbar element sets CSS custom properties on its style for thumb sizing and positioning. The specific variables depend on the scrollbar orientation.

CSS VariableDescription
--thumb-heightHeight of the vertical scrollbar thumb in pixels
--thumb-widthWidth of the horizontal scrollbar thumb in pixels
--thumb-offsetOffset position of the thumb along the scrollbar track

Defines passthrough(pt) options of ScrollAreaScrollbar component.

labeltypedescription
rootScrollAreaScrollbarPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ScrollAreaThumb#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaThumbInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaThumbInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaThumbInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaThumbPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaThumbInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"scrollarea"
data-part"thumb-y" or "thumb-x"

Defines passthrough(pt) options of ScrollAreaThumb component.

labeltypedescription
rootScrollAreaThumbPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ScrollAreaCorner#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ScrollAreaCornerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ScrollAreaCornerInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceScrollAreaCornerInstance—
The instance to pass to the component.
ptSafeRecord<ScrollAreaCornerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ScrollAreaCornerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"scrollarea"
data-part"corner"

Defines passthrough(pt) options of ScrollAreaCorner component.

labeltypedescription
rootScrollAreaCornerPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ScrollAreaThumbY#

Defines passthrough(pt) options of ScrollAreaThumbY component.

labeltypedescription
rootScrollAreaThumbYPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

ScrollAreaThumbX#

Defines passthrough(pt) options of ScrollAreaThumbX component.

labeltypedescription
rootScrollAreaThumbXPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Scrollbars use the scrollbar role with aria-controls referencing the scrollable content container and aria-orientation to indicate the scrolling direction.

Keyboard Support#

KeyFunction
tabMoves focus through the scrollable region.
down arrowScrolls content down when vertical scrolling is available.
up arrowScrolls content up when vertical scrolling is available.
left arrowScrolls content left when horizontal scrolling is available.
right arrowScrolls content right when horizontal scrolling is available.