Skip to content

Scroll Area

A native scroll container with Dify overlay scrollbars.

Recent activity

hero.tsx

Usage guidelines

  • Use ScrollArea for a fixed-size panel, list or code block whose content can overflow. Let the page itself scroll natively.
  • ScrollAreaViewport is the element that scrolls and takes focus. Put scroll refs, onScroll, role, the accessible name and overscroll behavior on the viewport, not on the root.
  • The viewport becomes a Tab stop whenever its content overflows, so name what it scrolls: add role="region" with aria-labelledby pointing at a visible title, otherwise with aria-label.
  • Wrap the content in ScrollAreaContent. It keeps the scrollbars in sync when the content changes size.
  • Base UI sets the viewport's overflow and the content's min-width inline. Override them with style, such as style={{ minWidth: 0 }} on ScrollAreaContent so a vertical list truncates long text; min-w-0 and overflow-* utilities do not apply.
  • Render one ScrollAreaScrollbar per scrolling axis. Add ScrollAreaCorner when both axes scroll.
  • ScrollAreaScrollbar stays hidden at rest and reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. Override className with pointer-events-auto opacity-100 if a surface requires a persistent scrollbar.

Anatomy

tsx
tsx

The root draws the focus ring above the content when the viewport has keyboard focus, so the ring is not clipped or masked by the scrolling content.

Examples

Truncating a vertical list

style={{ minWidth: 0 }} on ScrollAreaContent lets long file names truncate instead of adding a horizontal scroll.

truncation.tsx

Horizontal

Set orientation="horizontal" on the scrollbar for a row that overflows sideways.

horizontal.tsx

Scroll fade

The viewport exposes --scroll-area-overflow-y-start and --scroll-area-overflow-y-end. Use them in a mask so the edges fade only when there is more content in that direction, and give each var() a fallback so the mask is valid before hydration.

scroll-fade.tsx

Both axes

Render a vertical and a horizontal ScrollAreaScrollbar together with ScrollAreaCorner when content overflows in both directions, such as a wide log table.

both-axes.tsx

Keyboard

KeyAction
TabMoves focus to the viewport when its content overflows. The root draws the focus ring and reveals the scrollbar.
Down arroworUp arrowScrolls the focused viewport down or up.
Right arroworLeft arrowScrolls the focused viewport right or left.
PageDownorPageUpScrolls down or up by about one viewport height.
SpaceorShift+SpaceScrolls down or up by about one viewport height.
HomeorEndScrolls to the top or bottom.

API reference

ScrollArea

Groups a scrollable viewport with custom overlay scrollbars. Renders a <div> element.

ScrollAreaViewport owns scroll refs, events, and focus; use inline style to override Base UI's inline overflow on Viewport or minWidth on Content.

Base UI ScrollArea.Root docs

Data attributes
AttributeDescription
data-scrolling

Present when the user scrolls inside the scroll area.

data-has-overflow-x

Present when the scroll area content is wider than the viewport.

data-has-overflow-y

Present when the scroll area content is taller than the viewport.

data-overflow-x-start

Present when there is overflow on the horizontal start side.

data-overflow-x-end

Present when there is overflow on the horizontal end side.

data-overflow-y-start

Present when there is overflow on the vertical start side.

data-overflow-y-end

Present when there is overflow on the vertical end side.

CSS variables
VariableDescription
--scroll-area-corner-height

Values: number

The scroll area's corner height.

--scroll-area-corner-width

Values: number

The scroll area's corner width.

ScrollAreaContent

A container for the content of the scroll area. Renders a <div> element.

Base UI ScrollArea.Content docs

Data attributes
AttributeDescription
data-scrolling

Present when the user scrolls inside the scroll area.

data-has-overflow-x

Present when the scroll area content is wider than the viewport.

data-has-overflow-y

Present when the scroll area content is taller than the viewport.

data-overflow-x-start

Present when there is overflow on the horizontal start side.

data-overflow-x-end

Present when there is overflow on the horizontal end side.

data-overflow-y-start

Present when there is overflow on the vertical start side.

data-overflow-y-end

Present when there is overflow on the vertical end side.

ScrollAreaCorner

A small rectangular area that appears at the intersection of horizontal and vertical scrollbars. Renders a <div> element.

Base UI ScrollArea.Corner docs

ScrollAreaScrollbar

Overlay scrollbar track that reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. Renders a <div> element.

Base UI ScrollArea.Scrollbar docs

Data attributes
AttributeDescription
data-orientation

Values: 'horizontal' | 'vertical'

Indicates the orientation of the scrollbar.

data-hovering

Present when the pointer is over the scroll area.

data-scrolling

Present when the user scrolls inside the scroll area.

data-has-overflow-x

Present when the scroll area content is wider than the viewport.

data-has-overflow-y

Present when the scroll area content is taller than the viewport.

data-overflow-x-start

Present when there is overflow on the horizontal start side.

data-overflow-x-end

Present when there is overflow on the horizontal end side.

data-overflow-y-start

Present when there is overflow on the vertical start side.

data-overflow-y-end

Present when there is overflow on the vertical end side.

CSS variables
VariableDescription
--scroll-area-thumb-height

Values: number

The scroll area thumb's height.

--scroll-area-thumb-width

Values: number

The scroll area thumb's width.

ScrollAreaThumb

The draggable part of the scrollbar that indicates the current scroll position. Renders a <div> element.

Base UI ScrollArea.Thumb docs

Data attributes
AttributeDescription
data-orientation

Values: 'horizontal' | 'vertical'

Indicates the orientation of the scrollbar.

data-scrolling

Present when the user scrolls inside the scroll area.

ScrollAreaViewport

The actual scrollable container of the scroll area. Renders a <div> element.

Base UI ScrollArea.Viewport docs

Data attributes
AttributeDescription
data-scrolling

Present when the user scrolls inside the scroll area.

data-has-overflow-x

Present when the scroll area content is wider than the viewport.

data-has-overflow-y

Present when the scroll area content is taller than the viewport.

data-overflow-x-start

Present when there is overflow on the horizontal start side.

data-overflow-x-end

Present when there is overflow on the horizontal end side.

data-overflow-y-start

Present when there is overflow on the vertical start side.

data-overflow-y-end

Present when there is overflow on the vertical end side.

CSS variables
VariableDescription
--scroll-area-overflow-x-start

Values: number

The distance from the horizontal start edge in pixels.

--scroll-area-overflow-x-end

Values: number

The distance from the horizontal end edge in pixels.

--scroll-area-overflow-y-start

Values: number

The distance from the vertical start edge in pixels.

--scroll-area-overflow-y-end

Values: number

The distance from the vertical end edge in pixels.