# Scroll Area

> A scrollable viewport with custom overlay scrollbars, edge fade masks, and overscroll containment built on Base UI.

Canonical URL: https://taut-ui.com/docs/components/scroll-area

```tsx
import { Card } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Separator } from "@/components/ui/separator";

const tags = [
  "Base UI",
  "Tailwind CSS",
  "Next.js",
  "React",
  "TypeScript",
  "Class Variance Authority",
  "Lucide Icons",
  "Biome",
  "Jotai",
  "Fumadocs",
  "Shiki",
  "Zod",
];

export default function Particle() {
  return (
    <Card className="h-56 w-64 overflow-hidden">
      <ScrollArea overscrollContain>
        <div className="p-4">
          <h4 className="mb-2 font-medium text-foreground text-sm">Stack</h4>
          {tags.map((tag, index) => (
            <div key={tag}>
              <p className="py-2 text-muted-foreground text-sm">{tag}</p>
              {index < tags.length - 1 && <Separator />}
            </div>
          ))}
        </div>
      </ScrollArea>
    </Card>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/scroll-area.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/scroll-area.tsx"
"use client";

import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area";
import type React from "react";
import { cn } from "@/lib/utils";

export type ScrollAreaProps = ScrollAreaPrimitive.Root.Props & {
  scrollFade?: boolean;
  scrollbarGutter?: boolean;
  fill?: boolean;
  clampContentMinWidth?: boolean;
  overscrollContain?: boolean;
};

export function ScrollArea({
  className,
  children,
  scrollFade = false,
  scrollbarGutter = false,
  fill = false,
  clampContentMinWidth = true,
  overscrollContain = false,
  ...props
}: ScrollAreaProps): React.ReactElement {
  return (
    <ScrollAreaPrimitive.Root
      className={cn(
        "flex size-full min-h-0 flex-col [--fade-size:1.5rem]",
        className,
      )}
      data-slot="scroll-area"
      {...props}
    >
      <ScrollAreaPrimitive.Viewport
        className={cn(
          "h-full min-h-0 w-full flex-1 rounded-[inherit] outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
          "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
          overscrollContain &&
            "data-has-overflow-y:overscroll-y-contain data-has-overflow-x:overscroll-x-contain",
          scrollFade &&
            "mask-t-from-[calc(100%-min(var(--fade-size),var(--scroll-area-overflow-y-start,0rem)))] mask-r-from-[calc(100%-min(var(--fade-size),var(--scroll-area-overflow-x-end,0rem)))] mask-b-from-[calc(100%-min(var(--fade-size),var(--scroll-area-overflow-y-end,0rem)))] mask-l-from-[calc(100%-min(var(--fade-size),var(--scroll-area-overflow-x-start,0rem)))]",
          scrollbarGutter &&
            "data-has-overflow-y:pe-3 data-has-overflow-x:pb-3",
        )}
        data-slot="scroll-area-viewport"
      >
        <ScrollAreaPrimitive.Content
          className={fill ? "size-full" : undefined}
          data-slot="scroll-area-content"
          style={clampContentMinWidth ? { minWidth: 0 } : undefined}
        >
          {children}
        </ScrollAreaPrimitive.Content>
      </ScrollAreaPrimitive.Viewport>
      <ScrollBar orientation="vertical" />
      <ScrollBar orientation="horizontal" />
      <ScrollAreaPrimitive.Corner data-slot="scroll-area-corner" />
    </ScrollAreaPrimitive.Root>
  );
}

export type ScrollBarProps = ScrollAreaPrimitive.Scrollbar.Props;

export function ScrollBar({
  className,
  orientation = "vertical",
  ...props
}: ScrollBarProps): React.ReactElement {
  return (
    <ScrollAreaPrimitive.Scrollbar
      className={cn(
        "m-1 flex opacity-0 transition-opacity delay-300 duration-150 data-[orientation=horizontal]:h-1.5 data-[orientation=vertical]:w-1.5 data-[orientation=horizontal]:flex-col data-hovering:opacity-100 data-scrolling:opacity-100 data-hovering:delay-0 data-scrolling:delay-0 motion-reduce:transition-none",
        className,
      )}
      data-base-ui-swipe-ignore=""
      data-slot="scroll-area-scrollbar"
      orientation={orientation}
      {...props}
    >
      <ScrollAreaPrimitive.Thumb
        className="relative flex-1 rounded-full bg-[color-mix(in_oklab,var(--color-background),var(--color-foreground)_28%)] hover:bg-[color-mix(in_oklab,var(--color-background),var(--color-foreground)_48%)] active:bg-primary"
        data-slot="scroll-area-thumb"
      />
    </ScrollAreaPrimitive.Scrollbar>
  );
}

export { ScrollAreaPrimitive };
```

- Update the import paths to match your project setup.

## Usage [#usage]

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

```tsx
<ScrollArea className="h-56 w-64" scrollFade>
  <div className="p-4">
    {/* Scrollable content */}
  </div>
</ScrollArea>
```

## Examples [#examples]

### Scroll Fade [#scroll-fade]

```tsx
import { Card } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";

export default function Particle() {
  return (
    <Card className="h-56 w-80 overflow-hidden">
      <ScrollArea overscrollContain scrollFade>
        <div className="space-y-3 p-5 text-muted-foreground text-sm leading-6">
          <p>
            ScrollArea applies smooth edge fade masks automatically whenever
            content overflows along the vertical or horizontal axis.
          </p>
          <p>
            As you scroll down, the top mask fades in proportionally to the
            scroll offset, while the bottom mask fades out once you reach the
            end of the container.
          </p>
          <p>
            Combined with overscrollContain, wheel and touch gestures stay
            contained inside the panel without pulling the parent page along.
          </p>
          <p>
            Overlay scrollbars remain hidden at rest and appear cleanly on hover
            or active scrolling, keeping dense interfaces uncluttered.
          </p>
        </div>
      </ScrollArea>
    </Card>
  );
}
```

### Horizontal [#horizontal]

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

const items = [
  { label: "Surface", value: "01" },
  { label: "Motion", value: "02" },
  { label: "Shape", value: "03" },
  { label: "Color", value: "04" },
  { label: "Type", value: "05" },
  { label: "Depth", value: "06" },
  { label: "Focus", value: "07" },
];

export default function Particle() {
  return (
    <div className="w-80">
      <ScrollArea overscrollContain>
        <div className="flex w-max gap-3 py-1">
          {items.map((item) => (
            <div
              className="flex h-24 w-28 shrink-0 flex-col justify-between rounded-2xl bg-muted p-3.5 dark:bg-card"
              key={item.value}
            >
              <span className="font-mono text-muted-foreground text-xs">
                {item.value}
              </span>
              <span className="font-medium text-foreground text-sm">
                {item.label}
              </span>
            </div>
          ))}
        </div>
      </ScrollArea>
    </div>
  );
}
```

### Both Axes [#both-axes]

```tsx
import { Card } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";

const columns = ["Token", "Light", "Dark", "Taut", "Role"];

const rows = [
  ["--background", "#ffffff", "#121212", "oklch(0.19)", "Page canvas"],
  ["--foreground", "#262626", "#f5f5f5", "oklch(0.914)", "Primary text"],
  ["--card", "#ffffff", "#171717", "oklch(0.242)", "Surface low"],
  ["--popover", "#ffffff", "#1c1c1c", "oklch(0.284)", "Floating surface"],
  ["--primary", "#262626", "#f5f5f5", "oklch(0.827)", "Brand accent"],
  ["--secondary", "4% black", "4% white", "oklch(0.397)", "Tonal fill"],
  ["--muted", "4% black", "4% white", "oklch(0.284)", "Subtle surface"],
  ["--accent", "4% black", "4% white", "oklch(0.328)", "Hover surface"],
  [
    "--destructive",
    "oklch(0.55)",
    "oklch(0.58)",
    "oklch(0.838)",
    "Danger state",
  ],
  ["--ring", "#a3a3a3", "#737373", "oklch(0.827)", "Focus outline"],
];

export default function Particle() {
  return (
    <Card className="h-60 w-80 overflow-hidden">
      <ScrollArea overscrollContain>
        <div className="w-max p-4">
          <div className="grid grid-cols-[9rem_6.5rem_6.5rem_7.5rem_8rem] gap-3 pb-2 font-medium text-foreground text-xs">
            {columns.map((col) => (
              <span key={col}>{col}</span>
            ))}
          </div>
          <div className="flex flex-col divide-y divide-border">
            {rows.map((row) => (
              <div
                className="grid grid-cols-[9rem_6.5rem_6.5rem_7.5rem_8rem] gap-3 py-2 text-muted-foreground text-xs"
                key={row[0]}
              >
                <span className="font-mono text-foreground">{row[0]}</span>
                <span className="font-mono">{row[1]}</span>
                <span className="font-mono">{row[2]}</span>
                <span className="font-mono">{row[3]}</span>
                <span>{row[4]}</span>
              </div>
            ))}
          </div>
        </div>
      </ScrollArea>
    </Card>
  );
}
```

### Scrollbar Gutter [#scrollbar-gutter]

```tsx
import { Badge } from "@/components/ui/badge";
import { Card } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";

const endpoints = [
  { method: "GET", path: "/api/projects", status: "200" },
  { method: "POST", path: "/api/deployments", status: "201" },
  { method: "GET", path: "/api/tokens", status: "200" },
  { method: "PATCH", path: "/api/settings", status: "200" },
  { method: "DELETE", path: "/api/sessions", status: "204" },
  { method: "GET", path: "/api/members", status: "200" },
  { method: "POST", path: "/api/invites", status: "201" },
  { method: "GET", path: "/api/webhooks", status: "200" },
  { method: "GET", path: "/api/audit-logs", status: "200" },
];

export default function Particle() {
  return (
    <Card className="h-56 w-80 overflow-hidden">
      <ScrollArea overscrollContain scrollbarGutter>
        <div className="flex flex-col gap-1 p-3">
          {endpoints.map((ep) => (
            <div
              className="flex items-center justify-between gap-2 rounded-xl px-2.5 py-1.5 text-xs"
              key={`${ep.method}-${ep.path}`}
            >
              <span className="truncate font-mono text-foreground">
                <span className="me-2 text-muted-foreground">{ep.method}</span>
                {ep.path}
              </span>
              <Badge size="sm" variant="success">
                {ep.status}
              </Badge>
            </div>
          ))}
        </div>
      </ScrollArea>
    </Card>
  );
}
```

## API Reference [#api-reference]

### ScrollArea [#scrollarea]

Wraps Base UI `ScrollArea.Root`, `Viewport`, `Content`, both vertical and horizontal `ScrollBar`s, and `Corner`.

| Prop                   | Type                             | Default | Description                                                               |
| ---------------------- | -------------------------------- | ------- | ------------------------------------------------------------------------- |
| `scrollFade`           | `boolean`                        | `false` | Applies smooth edge fade masks along overflowing axes                     |
| `scrollbarGutter`      | `boolean`                        | `false` | Reserves padding along the scrollbar edge when content overflows          |
| `fill`                 | `boolean`                        | `false` | Expands the inner content wrapper to `size-full`                          |
| `clampContentMinWidth` | `boolean`                        | `true`  | Sets `min-width: 0` on the content element to prevent flex overflow       |
| `overscrollContain`    | `boolean`                        | `false` | Applies `overscroll-contain` on overflowing axes to stop scroll chaining  |
| `className`            | `string`                         | -       | Additional CSS classes applied to the root element                        |
| `...props`             | Base UI ScrollArea Root props    | -       | All other ScrollArea Root props are supported                             |

### ScrollBar [#scrollbar]

Overlay scrollbar track and draggable thumb that appears on hover or active scrolling.

| Prop          | Type                         | Default      | Description                                   |
| ------------- | ---------------------------- | ------------ | --------------------------------------------- |
| `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Scrollbar axis                                |
| `className`   | `string`                     | -            | Additional CSS classes                        |
| `...props`    | Base UI Scrollbar props      | -            | All standard scrollbar attributes             |
