Prototyper UI

Scroll Area

A scrollable container with custom styled scrollbars

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/scroll-area.json
npx shadcn@latest add https://prototyper-ui.com/r/scroll-area.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/scroll-area.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/scroll-area.json

This will add the following files to your project:

  • components/ui/scroll-area.tsx

Usage

import { ScrollArea } from "@/components/ui/scroll-area"

<ScrollArea className="h-72 w-48 rounded-md border">
  <div className="p-4">
    {/* Long content here */}
  </div>
</ScrollArea>

Anatomy

<ScrollArea>
  {/* ScrollArea.Viewport, ScrollBar, and ScrollArea.Corner are rendered internally */}
  <div>Your scrollable content</div>
</ScrollArea>
Sub-componentdata-slotPurposeRequired
ScrollAreascroll-areaRoot container with built-in viewport/scrollbarYes
ScrollBarscroll-area-scrollbarScrollbar track (vertical or horizontal)Internal
Viewportscroll-area-viewportScrollable viewport containerInternal
Thumbscroll-area-thumbDraggable scrollbar indicatorInternal

Note: The viewport, scrollbar, thumb, and corner are rendered automatically inside the ScrollArea component. You only need to provide child content.

Styling

Data Slots

Use data-slot attributes to target specific parts of the scroll area:

Slot nameElement
scroll-areaRoot wrapper
scroll-area-viewportScrollable viewport
scroll-area-scrollbarScrollbar track
scroll-area-thumbScrollbar thumb indicator

Customization Examples

/* Make the scrollbar wider */
[data-slot="scroll-area-scrollbar"] {
  @apply w-3.5;
}

/* Custom thumb color */
[data-slot="scroll-area-thumb"] {
  @apply bg-primary/50;
}
{/* Add horizontal scrollbar with the ScrollBar component */}
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"

<ScrollArea className="w-96 whitespace-nowrap rounded-md border">
  <div className="flex w-max space-x-4 p-4">
    {items.map((item) => (
      <div key={item} className="w-40 shrink-0">{item}</div>
    ))}
  </div>
  <ScrollBar orientation="horizontal" />
</ScrollArea>

API Reference

ScrollArea

Root component that provides a scrollable viewport with custom scrollbars. Renders a vertical scrollbar by default.

Prop

Type

All Base UI ScrollArea.Root props are forwarded via ...props.

ScrollBar

A scrollbar track with a draggable thumb. One vertical scrollbar is rendered by default inside ScrollArea. Use this component to add an additional horizontal scrollbar.

Prop

Type

All Base UI ScrollArea.Scrollbar props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyDescription
TabMoves focus into the scroll area viewport
ArrowUp / ArrowDownScrolls content vertically when viewport is focused
ArrowLeft / ArrowRightScrolls content horizontally when viewport is focused
PageUp / PageDownScrolls content by one page
Home / EndScrolls to the start or end of content

ARIA Attributes

  • The viewport is focusable with tabindex="0" and includes a focus-visible ring for keyboard users.
  • Scroll position is managed natively by the browser, providing standard scrolling behavior and screen reader compatibility.
  • The custom scrollbars are decorative overlays; actual scrolling relies on native browser scroll mechanics.
  • data-has-overflow-x and data-has-overflow-y attributes on the root indicate when content exceeds the viewport.
  • data-scrolling is present on the root during active scrolling.

On this page