# Scroll Area

> Custom scrollbar for React and shadcn: a thin overlay bar on a native scroller, with edge fades only where more remains.

A native scroller with a thin themed overlay scrollbar that thickens under the pointer, and edge fades that appear only when there is more to scroll. Base UI Scroll Area underneath.

Also known as a custom scrollbar.

- Tier: Free (MIT)
- Interaction: Scroll
- Page: https://eased.dev/components/scroll-area
- Installs: @base-ui/react
- Registry: https://eased.dev/r/scroll-area.json

## Install

```bash
npx shadcn add https://eased.dev/r/scroll-area.json
```

A native scroller on Base UI's Scroll Area, with a thin themed overlay scrollbar and edge fades that appear only where there is more to scroll.

## When to use

- A fixed-height list inside a card, panel or sidebar: an activity feed, a list of members, a log.
- A row of chips or filters that scrolls sideways on narrow screens: `orientation="horizontal"`.
- Anywhere the browser's default scrollbar would look out of place or take up width.

## When not to use

- The page itself: let the document scroll natively.
- Content that fits: a Scroll Area with nothing to scroll adds a wrapper and nothing else.
- Very long lists of thousands of rows: it renders every child, so pair it with a virtualiser or paginate with [Pagination](/components/pagination).

## Scroll Area vs the shadcn/ui Scroll Area

shadcn/ui's Scroll Area is a styled wrapper around a headless scroll area: it gives you a themed scrollbar, and you add a separate horizontal `ScrollBar` when content scrolls sideways. Eased's Scroll Area is an alternative built on the same idea, a native scroller with a custom bar, plus the details that usually get added by hand:

| | shadcn/ui Scroll Area | Eased Scroll Area |
| --- | --- | --- |
| Scrolling | Native | Native |
| Horizontal and both directions | Add a horizontal `ScrollBar` | `orientation="horizontal"` or `"both"` |
| Edge fades | Not included | Fade only where there is more to scroll (`fade`, 20px by default) |
| Named region | Add it yourself | `aria-label` makes the viewport a named region |

Eased's version also:

- hides the bar at rest and shows it while you scroll or point at it
- draws a 4px pill inside a 10px hit zone, so it is easy to grab, and thickens it to 6px under the pointer
- draws the focus ring inset, so the clipped viewport can't hide it
- keeps the page from scrolling once the area reaches its end

Install it next to the shadcn/ui component, or replace it: imports come from `@/components/eased/scroll-area/scroll-area`, so both can live in the same project while you switch over.

## FAQ

### How do I make a custom scrollbar in React?

Keep the browser's native scrolling and hide its scrollbar, then draw your own thumb sized and positioned from the scroll position. Scroll Area does this on Base UI's Scroll Area, so trackpads, touch, keyboard scrolling and find-in-page keep working.

### How do I add fade edges to a scrolling list?

Set `fade` on Scroll Area to the size of the fade in pixels. Each edge fades only while there is more content to scroll in that direction, so the top edge stays sharp until you scroll down.

### How do I make a horizontal scroll area?

Set `orientation="horizontal"` and give the content `w-max` in `contentClassName`, so it keeps its natural width and scrolls sideways.

### Is a custom scrollbar accessible?

It can be, as long as scrolling stays native. Name the region with `aria-label` so it is announced when it receives focus, and make sure the focus ring is visible. Keyboard users scroll it with the arrow keys, Page Up, Page Down, Home and End.

## Usage

```tsx activity-feed.tsx
import { ScrollArea } from "@/components/eased/scroll-area/scroll-area";

export function ActivityFeed({ events }: { events: { id: string; text: string }[] }) {
  return (
    <ScrollArea className="h-72" contentClassName="px-4 py-2" aria-label="Activity">
      <ul>
        {events.map((e) => (
          <li key={e.id} className="py-2 text-ui">{e.text}</li>
        ))}
      </ul>
    </ScrollArea>
  );
}
```

Size the root with `className` (`h-72`, `max-h-80`, or `flex-1 min-h-0` in a flex column), and put padding in `contentClassName` so it scrolls with the content.

## Examples

### Horizontal

A row of filter chips that scrolls sideways. Give the content `w-max` so it keeps its natural width.

```tsx
<ScrollArea orientation="horizontal" fade={24} aria-label="Filters" contentClassName="w-max px-4 py-2">
  <ToggleGroup variant="chips" multiple aria-label="Event types" defaultValue={["deploys"]}>
    <ToggleGroupItem value="deploys">Deploys</ToggleGroupItem>
    <ToggleGroupItem value="incidents">Incidents</ToggleGroupItem>
    <ToggleGroupItem value="comments">Comments</ToggleGroupItem>
  </ToggleGroup>
</ScrollArea>
```

### Scrolling to the latest item

`viewportRef` reaches the scrolling element, for `scrollTo` or scroll-linked effects.

```tsx
const viewport = useRef<HTMLDivElement>(null);
useEffect(() => {
  viewport.current?.scrollTo({ top: viewport.current.scrollHeight, behavior: "smooth" });
}, [messages.length]);

<ScrollArea viewportRef={viewport} className="min-h-0 flex-1" aria-label="Messages">…</ScrollArea>
```

## API reference

### ScrollArea

| Prop | Type | Default | Description |
|---|---|---|---|
| `orientation` | `"vertical" \| "horizontal" \| "both"` | `"vertical"` | Which way it scrolls. The other axis is locked; `"both"` draws both bars and fades all four edges. |
| `fade` | `number` | `20` | Edge feather in px, drawn only while there is more to scroll that way. `0` turns it off. |
| `className` | `string` | `""` | Classes for the root. Size it here. |
| `contentClassName` | `string` | `""` | Classes for the content wrapper. Put padding here. |
| `viewportRef` | `Ref<HTMLDivElement>` | | The scrolling element. |
| `aria-label` / `aria-labelledby` | `string` | | Names the scrollable region. |
| `style` | `CSSProperties` | | Root style. |
| `children` | `ReactNode` | | |

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Focuses the scrolling region while it overflows. |
| `↑` `↓` `←` `→` | Scroll the focused region. |
| `Page Up` / `Page Down`, `Home` / `End` | Scroll by a page, or to either end. |

These are the browser's own keys for a focused scroller.

## Accessibility

- With `aria-label` or `aria-labelledby`, the viewport becomes a named `role="region"`. Name it whenever it scrolls, because it is a tab stop.
- The focus ring is drawn inset on the root, because the faded, clipped viewport would hide an outline outside it.
- Scrolling stays native, so trackpads, touch, screen readers and find-in-page work as usual; `overscroll-behavior: contain` keeps the page from scrolling once the area reaches its end.
- In a vertical area, wide content shrinks to the viewport instead of pushing its last column out of view.

## Motion

The scrollbar is hidden at rest. It appears in 100ms while you scroll and in 150ms when the pointer is over it, and fades away over 300ms. The thumb is a 4px pill in a 10px hit zone that thickens to 6px and darkens under the pointer or while dragged, over 150ms, scaling rather than changing width. Each edge feathers in only as far as there is content past it, so a list at rest at its top shows no top fade at all and the fade grows as you scroll away. Reduced motion: the bar and the pill change without transitions.

## Notes for AI

Use ScrollArea for any bounded region that scrolls inside a page: size it with `className`, pad it with `contentClassName`, and always give it an `aria-label`. Use `orientation="horizontal"` with `w-max` content for chip rows.

Do not put padding or a fixed height on the content wrapper instead of the root, and do not add your own scrollbar styling or gradient overlays for the edges: the fade is a mask that already tracks the scroll position.

## Related

- [Progressive Blur](/components/progressive-blur): a scroll-linked blur at an edge, driven by `viewportRef`.
- [Toggle Group](/components/toggle-group): its chips variant is the row you would scroll sideways.

## Example

`components/eased/scroll-area/scroll-area-demo.tsx`

```tsx
"use client";

import { useRef, useState } from "react";
import { Avatar } from "../avatar/avatar";
import { DemoFrame } from "../lib/demo-frame";
import { ToggleGroup, ToggleGroupItem } from "../toggle-group/toggle-group";
import { ScrollArea } from "./scroll-area";

type Kind = "merged" | "review" | "comment" | "deploy" | "issue";

const EVENTS: { who: string; kind: Kind; what: string; ago: string }[] = [
  { who: "Maya Chen", kind: "merged", what: "Fix sheet scroll handoff on iOS", ago: "2m" },
  { who: "Jonas Weber", kind: "review", what: "Requested changes on #482", ago: "9m" },
  { who: "Priya Raman", kind: "deploy", what: "Shipped v0.14.2 to production", ago: "21m" },
  { who: "Leo Martins", kind: "comment", what: "“Thumb should thicken on hover”", ago: "34m" },
  { who: "Ana Sousa", kind: "issue", what: "Opened #491 Fades flicker in Safari 17", ago: "1h" },
  { who: "Maya Chen", kind: "review", what: "Approved #479 Progressive blur", ago: "1h" },
  { who: "Kenji Sato", kind: "merged", what: "Add superellipse fallback path", ago: "2h" },
  { who: "Jonas Weber", kind: "comment", what: "“Can we pin the corner exponent?”", ago: "2h" },
  { who: "Priya Raman", kind: "deploy", what: "Shipped v0.14.1 to staging", ago: "3h" },
  { who: "Ana Sousa", kind: "merged", what: "Tokenise scrollbar colours", ago: "4h" },
  { who: "Leo Martins", kind: "issue", what: "Opened #488 Rubber-band too loose", ago: "5h" },
  { who: "Kenji Sato", kind: "review", what: "Commented on #476", ago: "6h" },
  { who: "Maya Chen", kind: "deploy", what: "Rolled back v0.14.0", ago: "8h" },
  { who: "Jonas Weber", kind: "merged", what: "Velocity projection for pagers", ago: "Yesterday" },
  { who: "Ana Sousa", kind: "comment", what: "“Feather looks right at 20px”", ago: "Yesterday" },
  { who: "Priya Raman", kind: "issue", what: "Closed #470 Focus ring clipped", ago: "Mon" },
];

const FILTERS: { value: "all" | Kind; label: string }[] = [
  { value: "all", label: "All" },
  { value: "merged", label: "Merged" },
  { value: "review", label: "Reviews" },
  { value: "comment", label: "Comments" },
  { value: "deploy", label: "Deploys" },
  { value: "issue", label: "Issues" },
];

/** An activity feed: a horizontal filter row and a vertical list, both in Scroll Areas. */
export function ScrollAreaDemo() {
  const [filter, setFilter] = useState<"all" | Kind>("all");
  const list = useRef<HTMLDivElement>(null);
  const rows = filter === "all" ? EVENTS : EVENTS.filter((e) => e.kind === filter);

  return (
    <DemoFrame title="Activity" meta={`${rows.length} events`}>
      <ScrollArea orientation="horizontal" fade={24} className="shrink-0 border-b border-line-subtle" aria-label="Filters">
        <ToggleGroup
          value={[filter]}
          onValueChange={(v) => {
            if (!v[0]) return; // one filter is always on
            setFilter(v[0] as "all" | Kind);
            list.current?.scrollTo({ top: 0 });
          }}
          aria-label="Filter activity"
          variant="chips"
          className="w-max px-4 py-2.5"
        >
          {FILTERS.map((f) => (
            <ToggleGroupItem key={f.value} value={f.value}>
              {f.label}
            </ToggleGroupItem>
          ))}
        </ToggleGroup>
      </ScrollArea>

      <ScrollArea viewportRef={list} className="min-h-0 flex-1" aria-label="Activity">
        <ul>
          {rows.map((e, i) => (
            <li key={`${e.who}-${e.what}`} className={`flex h-12 items-center gap-3 px-4 ${i ? "border-t border-line-subtle" : ""}`}>
              <Avatar name={e.who} size="md" />
              <div className="min-w-0 flex-1">
                <p className="truncate text-ui-sm text-text">
                  <span className="font-medium">{e.who}</span> <span className="text-text-secondary">{e.what}</span>
                </p>
                <p className="text-ui-xs text-text-muted capitalize">{e.kind}</p>
              </div>
              <span className="shrink-0 text-ui-xs text-text-muted tabular-nums">{e.ago}</span>
            </li>
          ))}
        </ul>
      </ScrollArea>
    </DemoFrame>
  );
}
```
