Skip to content

Scroll Area

Native scrolling with a thin overlay scrollbar and edge fades.

Installation

  1. Add the registryOnce per project
  2. Add scroll-area

Usage

Give the scroll area a fixed size, or put it inside something that constrains it. The scrollbar shows while you hover or scroll.

Content fades at any edge it can scroll past, and focused content stays clear of the fade. Set --scroll-fade-size to change the fade's depth. The fades and the scrollbar update as the content grows or shrinks, such as when more rows load, without waiting for a scroll.

When the content overflows, the viewport joins the tab order so users can scroll it from the keyboard. If the content handles the keyboard itself, as a grid or a list of tabs does, pass viewportProps={{ tabIndex: -1 }} to remove the viewport from the tab order.

Composition

Examples

Without fades

scrollFade={false} turns the fades off.

Stick to bottom

stickToBottom starts scrolled to the bottom and, while someone is at the bottom, follows content added there, as a log or a chat does. Scrolling up keeps their place until they scroll back down. ScrollAreaScrollToBottom is a button that shows while there's more content below and scrolls to the bottom, smoothly unless reduced motion is on.

The button shows whenever the view isn't at the bottom. To show it only once someone has scrolled further up, pass that distance in pixels as overflowEdgeThreshold, such as overflowEdgeThreshold={{ yEnd: 48 }}. It sets when the root's data-overflow-* attributes apply, for each edge or for all four with a number. The fades follow the scroll position either way.

Horizontal

The content is as wide as the viewport, so text wraps and a list's items truncate rather than scrolling sideways. For content that scrolls sideways, give it a width of its own, such as w-max, or w-fit min-w-full to fill the viewport when it's narrower. Put its padding on the content too, since the viewport's padding doesn't extend past content that overflows it. Add <ScrollBar orientation="horizontal" /> to show a scrollbar for it.

Scrollbar gutter

The scrollbars float over the content, which works when the content has padding of its own. When it runs to the edge, as a row of chips does, scrollbarGutter adds room beside the content for each scrollbar while its axis overflows, so the scrollbar doesn't cover it. Set --scrollbar-size on the root to change both the room and the scrollbars' thickness, which is 0.75rem by default. Suggestion uses it for its scrolling row of prompts.

Hidden scrollbars

hideScrollbars leaves out the scrollbars. The content still scrolls by wheel, touch and keyboard, and the fades still show that there's more to see.

Props

Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.

ScrollArea

ScrollBar

ScrollAreaScrollToBottom