Scroll Area

New

Augments native scroll functionality with auto, hover, and always visibility modes, scrollbar variants, gutter reserve, keyboard navigation, and high-contrast support.

$ pnpm dlx shadcn@latest add @byphongphan/scroll-area
Requires @byphongphan in components.json
data-display
Loading preview...

Installation

Install the following dependencies:

$ pnpm add @base-ui/react class-variance-authority
Requires @byphongphan in components.json

Copy and paste the scroll-area component into your project.

components/ui/scroll-area.tsx

Update the import paths to match your project setup.

Usage

import { ScrollArea } from "@/registry/ui/scroll-area"
export function ScrollAreaDemo() { return ( <ScrollArea className="h-72 w-52 rounded-md border p-4" variant="default" size="default" type="hover" scrollbarGutter="auto" > <div className="space-y-2"> <h4 className="text-sm font-semibold">Title</h4> <p className="text-xs text-muted-foreground">Long content...</p> </div> </ScrollArea> )}

Examples

Horizontal Scrolling

ScrollArea with horizontal orientation for scrolling horizontal photo feeds, tag carousels, or metric cards.

Minimal Hairline

Ultra-compact zero-margin scrollbar for dense data tables, code editors, and side panels.

Bordered Track

Defined track border separating the scroll gutter from overflowing content.

Floating Island

Elevated floating thumb with soft shadow and inset padding for card surfaces and modal overlays.

Scroll Fade Mask

Top and bottom content fade masks indicating offscreen overflowing content.


Props

PropTypeDefaultDescription
type"hover" | "auto" | "always""hover"Visibility behavior for the scrollbars.
variant"default" | "minimal" | "bordered" | "floating""default"Visual aesthetic variant for the scrollbar track and thumb.
size"sm" | "default" | "lg""default"Thickness of the scrollbar track (4px, 6px, or 10px).
orientation"vertical" | "horizontal" | "both" | "none""both"Orientation of the automatically managed built-in scrollbars.
scrollbarGutterboolean | "auto" | "stable"falseControls reserve gutter spacing to eliminate layout shifts.
scrollFadebooleanfalseAdds smooth mask fade gradient at the overflowing edges.
overscrollContainbooleanfalsePrevents scroll chaining to parent containers on boundary edges.
fillbooleanfalseStretches viewport content container to 100% width and height.
clampContentMinWidthbooleantrueConstrains content min-width: 0 to enable responsive resizing.
classNameViewportstringundefinedAdditional CSS class names applied directly to the Viewport element.
tabIndexnumber0Keyboard focus tab index for keyboard-navigable scrolling.
rolestring"region"Accessible ARIA role for screen-reader region identification.

Command Palette

Quick search and commands navigation