Skip to Content
ComponentsScrollArea

ScrollArea

A custom scrollable container built on Base UI’s ScrollArea primitive. Hides native scrollbars and replaces them with styled overlays that appear on hover or scroll.

Import

import { ScrollArea } from "chunks-ui";

Basic Usage

Vertical scrolling — constrain height on the root and the scrollbar renders automatically:

<ScrollArea.Root className="h-64 w-full rounded border border-border"> <ScrollArea.Viewport> <ScrollArea.Content> {/* tall content */} </ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar orientation="vertical"> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> </ScrollArea.Root>

Horizontal Scrollbar

Set orientation="horizontal" on the scrollbar for wide content:

<ScrollArea.Root className="w-full rounded border border-border"> <ScrollArea.Viewport> <ScrollArea.Content>{/* wide content */}</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar orientation="horizontal"> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> </ScrollArea.Root>

Both Axes

Add both scrollbars and ScrollArea.Corner to fill the intersection:

<ScrollArea.Root className="h-48 w-full rounded border border-border"> <ScrollArea.Viewport> <ScrollArea.Content>{/* tall + wide content */}</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar orientation="vertical"> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Scrollbar orientation="horizontal"> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /> </ScrollArea.Root>

Compound Parts

PartDescription
ScrollArea.RootOuter container. Sets overflow: hidden and positions scrollbars.
ScrollArea.ViewportThe scrollable window. Native scrollbars are hidden via CSS.
ScrollArea.ContentWraps the actual content inside the viewport.
ScrollArea.ScrollbarThe custom scrollbar track. Fades in on hover/scroll via data-[hovering] and data-[scrolling].
ScrollArea.ThumbThe draggable scrollbar handle. Expands the hit area with a negative margin.
ScrollArea.CornerFills the corner square when both scrollbars are visible.

ScrollArea.Root Props

PropTypeDefaultDescription
classNamestringAdditional CSS classes. Set height here to enable vertical scrolling.

ScrollArea.Scrollbar Props

PropTypeDefaultDescription
orientation"vertical" | "horizontal""vertical"Which axis the scrollbar controls
classNamestringAdditional CSS classes
Last updated on