# Scroll Area

A Base UI scroll viewport with styled custom scrollbars.

A Base UI scroll viewport with styled custom scrollbars.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/scroll-area">Base UI Scroll Area</a> for
  upstream behavior and configuration. Zenos owns the public API, styling, and composition shown on
  this page.
</p>

```tsx
import { ScrollArea, Stack, Text } from "@zentara-co/zenos-ui";

function ScrollAreaExample() {
  const events = [
    "Policy updated",
    "New member invited",
    "Export completed",
    "Region added",
    "Alert acknowledged",
    "Access reviewed",
    "Integration connected",
    "Webhook delivered",
    "Backup finished",
    "Audit exported",
  ];

  return (
    <ScrollArea className="h-36 w-full max-w-sm rounded-lg border border-border-default">
      <Stack gap="1" className="p-2 pe-1">
        {events.map((event, index) => (
          <Stack key={event} gap="1" className="rounded-md px-3 py-2">
            <Text weight="medium">{event}</Text>
            <Text size="s" color="subtle">
              {index + 1} hour{index === 0 ? "" : "s"} ago
            </Text>
          </Stack>
        ))}
      </Stack>
    </ScrollArea>
  );
}
```

## Import

```tsx
import { ScrollArea } from "@zentara-co/zenos-ui";
```

## Constrain the viewport

Give `ScrollArea.Root` (or the convenient `ScrollArea` wrapper) a fixed height or width so content can overflow. The default composition includes a vertical scrollbar with `keepMounted` so overflow is measured reliably in constrained layouts.

## Horizontal

Use the compound parts when the scrolling axis differs from the convenient vertical composition. Keep wide children from shrinking so they produce horizontal overflow.

```tsx
import { ScrollArea, Stack, Text } from "@zentara-co/zenos-ui";

function ScrollAreaHorizontalExample() {
  return (
    <ScrollArea.Root className="h-36 w-full max-w-xl rounded-lg border border-border-default">
      <ScrollArea.Viewport>
        <ScrollArea.Content className="w-max p-3">
          <Stack direction="row" gap="3">
            {["Identity", "Devices", "Policies", "Sessions", "Audit log"].map((item) => (
              <div
                key={item}
                className="grid h-24 w-40 shrink-0 place-items-center rounded-md bg-background-neutral-subtle px-4 text-center"
              >
                <Text weight="medium">{item}</Text>
              </div>
            ))}
          </Stack>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar orientation="horizontal" keepMounted />
    </ScrollArea.Root>
  );
}
```

## Both axes

Render one scrollbar for each axis and add `ScrollArea.Corner` where they meet. This composition is useful for bounded data surfaces with content wider and taller than the viewport.

```tsx
import { ScrollArea, Text } from "@zentara-co/zenos-ui";

function ScrollAreaBothAxesExample() {
  const columns = ["Asset", "Owner", "Environment", "Status", "Last scanned"];

  return (
    <ScrollArea.Root className="h-52 w-full max-w-xl rounded-lg border border-border-default">
      <ScrollArea.Viewport>
        <ScrollArea.Content className="min-w-[42rem] p-3 pe-5 pb-5">
          <div className="grid grid-cols-5 gap-x-6 border-b border-border-default px-2 pb-2">
            {columns.map((column) => (
              <Text key={column} size="s" weight="bold">
                {column}
              </Text>
            ))}
          </div>
          {[
            "Gateway",
            "API",
            "Worker",
            "Console",
            "Database",
            "Storage",
            "Queue",
            "Cache",
            "Search",
            "Metrics",
          ].map((asset, index) => (
            <div
              key={asset}
              className="grid grid-cols-5 gap-x-6 border-b border-border-default px-2 py-3 last:border-0"
            >
              <Text>{asset}</Text>
              <Text>Platform team</Text>
              <Text>{index % 2 === 0 ? "Production" : "Staging"}</Text>
              <Text>{index % 3 === 0 ? "Review" : "Healthy"}</Text>
              <Text>{index + 2} hours ago</Text>
            </div>
          ))}
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar orientation="vertical" keepMounted />
      <ScrollArea.Scrollbar orientation="horizontal" keepMounted />
      <ScrollArea.Corner />
    </ScrollArea.Root>
  );
}
```

## Custom styling

Every compound part accepts `className`, so the bounded surface, content, scrollbar track, and thumb can share a branded treatment without changing scrolling behavior. Compose `ScrollArea.Thumb` explicitly when its styling differs from the default thumb. Stable `data-slot` attributes are also available for parent-scoped selectors.

```tsx
import { ScrollArea, Stack, Text } from "@zentara-co/zenos-ui";

function ScrollAreaCustomScrollbarExample() {
  return (
    <ScrollArea.Root className="h-52 w-full max-w-sm rounded-xl border border-border-accent-teal-default bg-background-accent-teal-subtlest-default shadow-raised">
      <ScrollArea.Viewport tabIndex={0} aria-label="Deployment activity">
        <ScrollArea.Content className="p-3 pe-5">
          <Stack gap="2">
            {Array.from({ length: 12 }, (_, index) => (
              <div
                key={index}
                className="rounded-lg bg-background-neutral-card px-3 py-2 text-text-accent-teal-bolder shadow-raised"
              >
                <Text weight="medium">Deployment {index + 1}</Text>
                <Text size="s" color="subtle">
                  Completed successfully
                </Text>
              </div>
            ))}
          </Stack>
        </ScrollArea.Content>
      </ScrollArea.Viewport>
      <ScrollArea.Scrollbar
        className="w-3 bg-background-accent-teal-subtlest-hover p-1"
        keepMounted
      >
        <ScrollArea.Thumb className="bg-background-accent-teal-bolder-default hover:bg-background-accent-teal-bolder-hover" />
      </ScrollArea.Scrollbar>
    </ScrollArea.Root>
  );
}
```

## Anatomy

```text
ScrollArea.Root
ScrollArea.Viewport
ScrollArea.Content
ScrollArea.Scrollbar
ScrollArea.Thumb
ScrollArea.Corner
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| children | ReactNode | — | Scrollable content used by the convenient composition. |
| Scrollbar.orientation | "vertical" \| "horizontal" | "vertical" | Axis controlled by this scrollbar. |
| Scrollbar.children | ReactNode | — | Custom thumb content. A styled Thumb is supplied by default. |
| Scrollbar.keepMounted | boolean | true | Keeps the scrollbar mounted while overflow is measured in constrained layouts. |
| native props | React.Base UI ScrollArea props | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

The viewport retains native scrolling behavior for wheel, touch, and keyboard input. Give a focused viewport an accessible name when its surrounding context does not already describe the region. Keep ordinary page content in the document scroll flow; use ScrollArea for intentionally bounded regions. Scrollbar thumbs are visual pointer controls and do not replace keyboard scrolling of the viewport.

Source: https://zenos-ui.pages.dev/components/scroll-area/