# Scroll Area

A scrolling region with a thin scrollbar that shows only while it is used.

A region that scrolls with a thin scrollbar that shows only while it is used. A region that scrolls with a thin overlay scrollbar of the system's own instead of the platform's: it takes no room, shows while the pointer is over the region or while it scrolls, and fades out a second after. Native scrolling underneath (wheel, touch, keyboard). Give the root a height (or a max-height) and, for sideways scrolling, content wider than it. Behaviour from the Zag scroll-area machine through Ark UI.

Kind: component · Category: Display · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `scroll-area` machine, through Ark UI

## Add

```bash
npx fndn add scroll-area
```

It writes the folder `scroll-area/` into the project's ui folder (`index.ts`, `scroll-area.tsx`, `ScrollArea.vue`, `ScrollArea.svelte`, `scroll-area.recipe.ts`). First time: [Installation](/installation.md).

## Usage

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

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

```svelte
import { ScrollArea } from "$lib/components/ui/scroll-area";
```

## Parts

In the DOM the root carries `data-slot="scroll-area"` and each part `data-slot="scroll-area-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `scroll-area` |  | Ark's root: data-overflow-x / data-overflow-y while there is more to scroll; a flex column so the viewport takes its height or max-height. |
| `viewport` | `div` | `scroll-area-viewport` |  | The native scroller with its own scrollbar hidden; at its end the page scrolls on (sideways overscroll is kept in). Focusable (tabindex 0) while it overflows, with the focus ring drawn inside it; data-at-top / -bottom / -left / -right from the engine. |
| `content` | `div` | `scroll-area-content` |  | The caller's content. vertical (the default): exactly as wide as the viewport (the engine's min-width: fit-content is taken back), so a row inside can truncate; a word longer than the region breaks (overflow-wrap: break-word). horizontal and both: at least as wide as it needs (min-width: fit-content), so it scrolls sideways. |
| `scrollbar` | `div` | `scroll-area-scrollbar` | repeats | One per scrolling direction (data-orientation vertical \| horizontal), positioned by the engine at the end edge or the bottom: 10px thick with 2px padding, transparent. Hidden while its direction does not overflow; opacity 0, then 1 while the pointer is over the region (data-hover), while it scrolls (data-scrolling) or while its thumb is dragged. |
| `thumb` | `div` | `scroll-area-thumb` | repeats | The draggable thumb: 6px, rounded pill, ink-3 at 45% (65% while hovered, 80% while dragged); its length and offset come from the engine. |
| `corner` | `div` | `scroll-area-corner` | optional | Where the two scrollbars meet (orientation both); empty. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `orientation` | `"vertical" \| "horizontal" \| "both"` | `"vertical"` | Which scrollbars it draws (the viewport scrolls whichever way its content overflows). vertical also keeps the content to the viewport's width, so text inside truncates or wraps instead of widening it. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Slots

| Slot | Content |
| --- | --- |
| `default` | The scrolled content. |

## States

`hover`, `scrolling`, `dragging`, `focus-visible`

## Keyboard and accessibility

Role: none (a presentation wrapper around a native scroller).

Keyboard:

- Tab reaches the viewport while it overflows (and before its focusable content); the arrow keys, Page Up / Page Down, Home / End and Space scroll it natively
- Focusable content inside it scrolls into view when it takes focus

Notes:

- The scrollbars are pointer affordances only: they are not focusable and carry no role; scrolling stays native.
- Name the region from outside when it matters (aria-label on the root lands on the root element).

## Motion

- scrollbar: fades in and out (opacity over duration.base, ease) on hover and scroll; hidden one second after the last scroll (the engine's timeout)
- thumb: colour over duration.base; its position follows the scroll exactly (no transition)
- first paint: nothing plays (the scrollbars start hidden)

## Tokens

`color.ink-3`, `radius.pill`, `duration.base`

## Examples

### Recent activity in a panel

React · `recent-activity.tsx`

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

const events = [
  { id: 1, who: "Maya Chen", what: "deployed web-app to Production", when: "2 min ago" },
  { id: 2, who: "Daniel Okafor", what: "merged #482 Add retry to webhook delivery", when: "14 min ago" },
  { id: 3, who: "Priya Raman", what: "invited aiko@northwind.example", when: "1 h ago" },
  { id: 4, who: "Lucas Moreau", what: "rolled back billing-api on Staging", when: "3 h ago" },
  { id: 5, who: "Aiko Tanaka", what: "created the branch feat/usage-alerts", when: "Yesterday" },
  { id: 6, who: "Sofia Alvarez", what: "rotated the API key nw_live_…4f2a", when: "Yesterday" },
  { id: 7, who: "Jonas Weber", what: "changed the plan from Team to Business", when: "Nov 12, 2026" },
  { id: 8, who: "Maya Chen", what: "created the project data-pipeline", when: "Nov 10, 2026" },
];

export default function RecentActivity() {
  return (
    <ScrollArea className="h-[136px] w-full" aria-label="Recent activity">
      <ul className="flex flex-col gap-3 pe-3 text-sm">
        {events.map((event) => (
          <li key={event.id}>
            <p className="text-ink-2"><span className="font-medium text-ink">{event.who}</span> {event.what}</p>
            <p className="text-xs text-ink-2">{event.when}</p>
          </li>
        ))}
      </ul>
    </ScrollArea>
  );
}
```

Vue · `recent-activity.vue`

```vue
<script setup lang="ts">
import { ScrollArea } from "@/components/ui/scroll-area";

const events = [
  { id: 1, who: "Maya Chen", what: "deployed web-app to Production", when: "2 min ago" },
  { id: 2, who: "Daniel Okafor", what: "merged #482 Add retry to webhook delivery", when: "14 min ago" },
  { id: 3, who: "Priya Raman", what: "invited aiko@northwind.example", when: "1 h ago" },
  { id: 4, who: "Lucas Moreau", what: "rolled back billing-api on Staging", when: "3 h ago" },
  { id: 5, who: "Aiko Tanaka", what: "created the branch feat/usage-alerts", when: "Yesterday" },
  { id: 6, who: "Sofia Alvarez", what: "rotated the API key nw_live_…4f2a", when: "Yesterday" },
  { id: 7, who: "Jonas Weber", what: "changed the plan from Team to Business", when: "Nov 12, 2026" },
  { id: 8, who: "Maya Chen", what: "created the project data-pipeline", when: "Nov 10, 2026" },
];
</script>

<template>
  <ScrollArea class="h-[136px] w-full" aria-label="Recent activity">
    <ul class="flex flex-col gap-3 pe-3 text-sm">
      <li v-for="event in events" :key="event.id">
        <p class="text-ink-2"><span class="font-medium text-ink">{{ event.who }}</span> {{ event.what }}</p>
        <p class="text-xs text-ink-2">{{ event.when }}</p>
      </li>
    </ul>
  </ScrollArea>
</template>
```

Svelte · `recent-activity.svelte`

```svelte
<script lang="ts">
  import { ScrollArea } from "$lib/components/ui/scroll-area";

  const events = [
    { id: 1, who: "Maya Chen", what: "deployed web-app to Production", when: "2 min ago" },
    { id: 2, who: "Daniel Okafor", what: "merged #482 Add retry to webhook delivery", when: "14 min ago" },
    { id: 3, who: "Priya Raman", what: "invited aiko@northwind.example", when: "1 h ago" },
    { id: 4, who: "Lucas Moreau", what: "rolled back billing-api on Staging", when: "3 h ago" },
    { id: 5, who: "Aiko Tanaka", what: "created the branch feat/usage-alerts", when: "Yesterday" },
    { id: 6, who: "Sofia Alvarez", what: "rotated the API key nw_live_…4f2a", when: "Yesterday" },
    { id: 7, who: "Jonas Weber", what: "changed the plan from Team to Business", when: "Nov 12, 2026" },
    { id: 8, who: "Maya Chen", what: "created the project data-pipeline", when: "Nov 10, 2026" },
  ];
</script>

<ScrollArea class="h-[136px] w-full" aria-label="Recent activity">
  <ul class="flex flex-col gap-3 pe-3 text-sm">
    {#each events as event (event.id)}
      <li>
        <p class="text-ink-2"><span class="font-medium text-ink">{event.who}</span> {event.what}</p>
        <p class="text-xs text-ink-2">{event.when}</p>
      </li>
    {/each}
  </ul>
</ScrollArea>
```

### Release notes in a card

React · `release-notes.tsx`

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

const notes = [
  "Usage alerts: get an email when a project reaches 80% and 100% of its monthly build minutes. Set the thresholds in Settings → Billing.",
  "Webhook deliveries now retry five times with exponential backoff before they are marked as failed. Failed deliveries can be replayed from the log for 30 days.",
  "Preview deployments get a comment on their pull request with the URL and the build time.",
  "Fixed: invoices for workspaces that changed plans in the middle of a month rounded the prorated amount down by one cent.",
];

export default function ReleaseNotes() {
  return (
    <ScrollArea className="h-48 w-80 max-w-full rounded-card bg-surface shadow-card" aria-label="What’s new in v2.14">
      <div className="flex flex-col gap-3 p-4 text-sm leading-normal text-ink-2">
        <p className="font-medium text-ink">What’s new in v2.14 · Nov 14, 2026</p>
        {notes.map((note) => (
          <p key={note}>{note}</p>
        ))}
      </div>
    </ScrollArea>
  );
}
```

Vue · `release-notes.vue`

```vue
<script setup lang="ts">
import { ScrollArea } from "@/components/ui/scroll-area";

const notes = [
  "Usage alerts: get an email when a project reaches 80% and 100% of its monthly build minutes. Set the thresholds in Settings → Billing.",
  "Webhook deliveries now retry five times with exponential backoff before they are marked as failed. Failed deliveries can be replayed from the log for 30 days.",
  "Preview deployments get a comment on their pull request with the URL and the build time.",
  "Fixed: invoices for workspaces that changed plans in the middle of a month rounded the prorated amount down by one cent.",
];
</script>

<template>
  <ScrollArea class="h-48 w-80 max-w-full rounded-card bg-surface shadow-card" aria-label="What’s new in v2.14">
    <div class="flex flex-col gap-3 p-4 text-sm leading-normal text-ink-2">
      <p class="font-medium text-ink">What’s new in v2.14 · Nov 14, 2026</p>
      <p v-for="note in notes" :key="note">{{ note }}</p>
    </div>
  </ScrollArea>
</template>
```

Svelte · `release-notes.svelte`

```svelte
<script lang="ts">
  import { ScrollArea } from "$lib/components/ui/scroll-area";

  const notes = [
    "Usage alerts: get an email when a project reaches 80% and 100% of its monthly build minutes. Set the thresholds in Settings → Billing.",
    "Webhook deliveries now retry five times with exponential backoff before they are marked as failed. Failed deliveries can be replayed from the log for 30 days.",
    "Preview deployments get a comment on their pull request with the URL and the build time.",
    "Fixed: invoices for workspaces that changed plans in the middle of a month rounded the prorated amount down by one cent.",
  ];
</script>

<ScrollArea class="h-48 w-80 max-w-full rounded-card bg-surface shadow-card" aria-label="What’s new in v2.14">
  <div class="flex flex-col gap-3 p-4 text-sm leading-normal text-ink-2">
    <p class="font-medium text-ink">What’s new in v2.14 · Nov 14, 2026</p>
    {#each notes as note (note)}
      <p>{note}</p>
    {/each}
  </div>
</ScrollArea>
```

### Preview deployments, sideways

React · `preview-deploys.tsx`

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

const previews = [
  { branch: "feat/usage-alerts", status: "Ready", tone: "green", when: "2 min ago" },
  { branch: "fix/invoice-rounding", status: "Building", tone: "accent", when: "Just now" },
  { branch: "chore/upgrade-vite", status: "Failed", tone: "red", when: "1 h ago" },
  { branch: "feat/sso", status: "Ready", tone: "green", when: "3 h ago" },
  { branch: "docs/webhook-retries", status: "Ready", tone: "green", when: "Yesterday" },
] as const;

export default function PreviewDeploys() {
  return (
    <ScrollArea orientation="horizontal" className="w-full" aria-label="Preview deployments">
      <ul className="flex w-max gap-2 pb-3">
        {previews.map((preview) => (
          <li key={preview.branch} className="flex w-44 shrink-0 flex-col gap-2 rounded-card bg-surface p-3 shadow-card">
            <p className="truncate text-sm font-medium text-ink" title={preview.branch}>{preview.branch}</p>
            <div className="flex items-center justify-between gap-2">
              <StatusPill tone={preview.tone} size="sm">{preview.status}</StatusPill>
              <span className="text-xs text-ink-2">{preview.when}</span>
            </div>
          </li>
        ))}
      </ul>
    </ScrollArea>
  );
}
```

Vue · `preview-deploys.vue`

```vue
<script setup lang="ts">
import { ScrollArea } from "@/components/ui/scroll-area";
import { StatusPill } from "@/components/ui/status-pill";

const previews = [
  { branch: "feat/usage-alerts", status: "Ready", tone: "green", when: "2 min ago" },
  { branch: "fix/invoice-rounding", status: "Building", tone: "accent", when: "Just now" },
  { branch: "chore/upgrade-vite", status: "Failed", tone: "red", when: "1 h ago" },
  { branch: "feat/sso", status: "Ready", tone: "green", when: "3 h ago" },
  { branch: "docs/webhook-retries", status: "Ready", tone: "green", when: "Yesterday" },
] as const;
</script>

<template>
  <ScrollArea orientation="horizontal" class="w-full" aria-label="Preview deployments">
    <ul class="flex w-max gap-2 pb-3">
      <li v-for="preview in previews" :key="preview.branch" class="flex w-44 shrink-0 flex-col gap-2 rounded-card bg-surface p-3 shadow-card">
        <p class="truncate text-sm font-medium text-ink" :title="preview.branch">{{ preview.branch }}</p>
        <div class="flex items-center justify-between gap-2">
          <StatusPill :tone="preview.tone" size="sm">{{ preview.status }}</StatusPill>
          <span class="text-xs text-ink-2">{{ preview.when }}</span>
        </div>
      </li>
    </ul>
  </ScrollArea>
</template>
```

Svelte · `preview-deploys.svelte`

```svelte
<script lang="ts">
  import { ScrollArea } from "$lib/components/ui/scroll-area";
  import { StatusPill } from "$lib/components/ui/status-pill";

  const previews = [
    { branch: "feat/usage-alerts", status: "Ready", tone: "green", when: "2 min ago" },
    { branch: "fix/invoice-rounding", status: "Building", tone: "accent", when: "Just now" },
    { branch: "chore/upgrade-vite", status: "Failed", tone: "red", when: "1 h ago" },
    { branch: "feat/sso", status: "Ready", tone: "green", when: "3 h ago" },
    { branch: "docs/webhook-retries", status: "Ready", tone: "green", when: "Yesterday" },
  ] as const;
</script>

<ScrollArea orientation="horizontal" class="w-full" aria-label="Preview deployments">
  <ul class="flex w-max gap-2 pb-3">
    {#each previews as preview (preview.branch)}
      <li class="flex w-44 shrink-0 flex-col gap-2 rounded-card bg-surface p-3 shadow-card">
        <p class="truncate text-sm font-medium text-ink" title={preview.branch}>{preview.branch}</p>
        <div class="flex items-center justify-between gap-2">
          <StatusPill tone={preview.tone} size="sm">{preview.status}</StatusPill>
          <span class="text-xs text-ink-2">{preview.when}</span>
        </div>
      </li>
    {/each}
  </ul>
</ScrollArea>
```

## Recipe

`scroll-area.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* scroll-area — a native scroller with an overlay scrollbar of the system's own (Zag scroll-area
 * through Ark UI). Sizes have no model in the system: a 10px bar with 2px padding and a 6px thumb,
 * ink-3 at 45% (65% hovered, 80% dragged), so it reads on surface, canvas and inset alike, light or dark.
 *
 * The root is a flex column, so a height or a max-height given to it sizes the viewport
 * (min-h-0 lets it shrink below its content). The viewport hides the platform's scrollbar and
 * keeps scrolling native; it is focusable while it overflows (the engine), with the focus ring
 * drawn inside it so the root never clips it. The engine places each scrollbar absolutely (end
 * edge, bottom) and moves the thumb with a transform; we only show the bar while the pointer is
 * over the region, while it scrolls or while the thumb is dragged, and hide a bar whose direction
 * does not overflow. Parts are found by data-slot; the root slot is `base`.
 *
 * The engine gives the content `min-width: fit-content` so a wide child can scroll sideways. A
 * region that scrolls only vertically (orientation vertical, the default) takes it back: the content
 * is as wide as the viewport, so a row inside can truncate (an ellipsis, a min-w-0 flex child)
 * instead of stretching the content past the viewport; a word longer than the region breaks
 * (overflow-wrap: break-word, which leaves min-content alone) rather than poking out sideways.
 * horizontal and both keep the engine's. */

export const scrollArea = tv({
  slots: {
    base: "relative flex min-h-0 min-w-0 flex-col",
    viewport: [
      "min-h-0 w-full flex-1 rounded-[inherit] overscroll-x-contain",
      "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
      "focus-visible:outline-offset-[-2px]",
    ],
    content: "",
    scrollbar: [
      "flex p-0.5 opacity-0 select-none touch-none motion-opacity-base",
      "data-hover:opacity-100 data-scrolling:opacity-100 data-dragging:opacity-100",
      "data-[orientation=vertical]:w-2.5 data-[orientation=vertical]:flex-col",
      "data-[orientation=horizontal]:h-2.5 data-[orientation=horizontal]:flex-row",
      "data-[orientation=vertical]:not-data-overflow-y:hidden data-[orientation=horizontal]:not-data-overflow-x:hidden",
    ],
    thumb: [
      "shrink-0 rounded-pill bg-ink-3/45 motion-colors-base",
      "hover:bg-ink-3/65 data-dragging:bg-ink-3/80",
      "data-[orientation=vertical]:w-full data-[orientation=horizontal]:h-full",
    ],
    corner: "",
  },
  variants: {
    orientation: {
      /* over the engine's inline min-width (hence the !) */
      vertical: { content: "min-w-0! wrap-break-word" },
      horizontal: {},
      both: {},
    },
  },
  defaultVariants: { orientation: "vertical" },
});

export type ScrollAreaRecipeProps = VariantProps<typeof scrollArea>;
```
