Scroll Area
A scrollable container with custom-styled scrollbars.
ScrollAreaExample
Examples
Horizontal scrolling
Use the same ScrollArea component for horizontally scrollable content. Scrollbars automatically adapt to the content direction.
ScrollAreaHorizontalExample
Installation
Copy the source code below into your project:
import { ScrollArea as BaseScrollArea } from "@base-ui/react/scroll-area";
import { cn } from "@/lib/utils";
function ScrollArea({
className,
children,
viewportProps,
...props
}: { viewportProps?: BaseScrollArea.Viewport.Props } & BaseScrollArea.Root.Props) {
return (
<BaseScrollArea.Root className={cn("size-full min-h-0", className)} {...props}>
<BaseScrollArea.Viewport
{...viewportProps}
className={cn(
"size-full overscroll-contain rounded-[inherit] outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
viewportProps?.className,
)}
data-slot="scroll-area-viewport"
>
{children}
</BaseScrollArea.Viewport>
<ScrollBar orientation="vertical" />
<ScrollBar orientation="horizontal" />
<BaseScrollArea.Corner data-slot="scroll-area-corner" />
</BaseScrollArea.Root>
);
}
function ScrollBar({
className,
orientation = "vertical",
...props
}: BaseScrollArea.Scrollbar.Props) {
return (
<BaseScrollArea.Scrollbar
className={cn(
"pointer-events-none flex justify-center rounded opacity-0 transition-opacity delay-300 data-hovering:pointer-events-auto data-hovering:opacity-100 data-hovering:delay-0 data-hovering:duration-75 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:delay-0 data-scrolling:duration-75",
"m-1 data-[orientation=horizontal]:h-1 data-[orientation=horizontal]:flex-col data-[orientation=vertical]:w-1",
className,
)}
data-slot="scroll-area-scrollbar"
orientation={orientation}
{...props}
>
<BaseScrollArea.Thumb
className="relative flex-1 rounded-full bg-muted-foreground/30"
data-slot="scroll-area-thumb"
/>
</BaseScrollArea.Scrollbar>
);
}
export { ScrollArea, ScrollBar };API Reference
ScrollArea
The ScrollArea component extends the Base UI ScrollArea.Root props and adds the following:
| Prop | Type | Default | Description |
|---|---|---|---|
| viewportProps | BaseScrollArea.Viewport.Props | - | Props forwarded to the underlying Viewport component. |
ScrollBar
The ScrollBar component extends the Base UI ScrollArea.Scrollbar props and adds the following:
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | "vertical" | "horizontal" | "vertical" | Orientation of the scrollbar. |