Scroll Area

The React Scroll Area component creates a scrollable container with custom scrollbars. It lets users scroll through content while keeping full control over the look and behavior.

It is useful when the content is larger than its container. For example, you can use it for long lists, tables, logs, or side panels with fixed height.

Built with Base UI and styled using Tailwind CSS, it supports vertical and horizontal scrolling, keyboard navigation, and accessible interactions.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add scroll-area

Anatomy

Import the component parts and combine them to create a scrollable area.

import {
  ScrollArea,
  ScrollAreaViewport,
  ScrollBar
} from "@/components/scroll-area";

export const ScrollAreaExample = () => (
  <ScrollArea>
    <ScrollAreaViewport>{/* Scrollable Content */}</ScrollAreaViewport>
    <ScrollBar orientation="vertical" />
    <ScrollBar orientation="horizontal" />
  </ScrollArea>
);

Examples

Basic Vertical Scroll

The most common use case for a scroll area, providing a custom vertical scrollbar for long lists or text blocks.

Horizontal Scroll

Use the orientation="horizontal" prop on the ScrollBar component to enable horizontal scrolling for wide content like carousels or data tables.

Both Axes

Enable both vertical and horizontal scrollbars for large content areas that exceed the container in both dimensions.

API Reference

ScrollArea

The root component that groups all parts and manages the scroll state.

PropTypeDefaultDescription
overflowEdgeThresholdnumber | { xStart?: number; xEnd?: number; yStart?: number; yEnd?: number } | undefined0Threshold in pixels before overflow edge attributes are applied.
classNamestring-Additional CSS classes for the root element.

ScrollAreaViewport

The actual scrollable container.

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the viewport.

ScrollBar

The scrollbar track and thumb component.

PropTypeDefaultDescription
orientation'vertical' | 'horizontal''vertical'The direction of movement for the scrollbar.
keepMountedbooleanfalseWhether to keep the element in the DOM when not scrollable.
classNamestring-Additional CSS classes for the scrollbar track.

Accessibility

  • Keyboard support: Users can scroll the content using keyboard keys when the scroll area is focused.
  • Scrollable container: The ScrollAreaViewport acts as the main scrollable region and should contain all scrollable content.
  • Custom scrollbars: Scrollbars are interactive and support mouse and touch drag.
  • Orientation support: Supports vertical and horizontal scrolling based on content size and scrollbar configuration.
  • Screen reader support: Use a clear structure and meaningful content within the scroll area so screen readers can interpret it correctly.