# Scroll Area

URL: https://ark-ui.com/docs/components/scroll-area
Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/scroll-area.mdx

A custom scrollable area component with styled scrollbars.

---

<ComponentPreview id="ScrollArea" />

## Anatomy

<Anatomy id="scroll-area" />

```tsx
<ScrollArea.Root>
  <ScrollArea.Viewport>
    <ScrollArea.Content />
  </ScrollArea.Viewport>
  <ScrollArea.Scrollbar>
    <ScrollArea.Thumb />
  </ScrollArea.Scrollbar>
  <ScrollArea.Corner />
</ScrollArea.Root>
```

## Required style

It's important to note that the scroll area requires the following styles on the `ScrollArea.Viewport` element to hide
the native scrollbar:

```css
[data-scope='scroll-area'][data-part='viewport'] {
  scrollbar-width: none;
  &::-webkit-scrollbar {
    display: none;
  }
}
```

## Examples

### Basic

Create a basic scrollable area with custom scrollbar.

**Example: basic**

```ripple
import { ScrollArea } from 'ark-ripple/scroll-area';
import styles from 'styles/scroll-area.module.css';

export component Basic() {
  <ScrollArea.Root class={styles.Root}>
    <ScrollArea.Viewport class={styles.Viewport}>
      <ScrollArea.Content class={styles.Content}>
        <p class={styles.Paragraph}>
          {'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar orientation="vertical" class={styles.Scrollbar}>
      <ScrollArea.Thumb class={styles.Thumb} />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner class={styles.Corner} />
  </ScrollArea.Root>
}

```

### Horizontal

Configure the scroll area for horizontal scrolling only.

**Example: horizontal**

```ripple
import { ScrollArea } from 'ark-ripple/scroll-area';
import styles from 'styles/scroll-area.module.css';

export component Horizontal() {
  <ScrollArea.Root class={styles.Root} style="height: auto">
    <ScrollArea.Viewport class={styles.Viewport}>
      <ScrollArea.Content class={styles.Content}>
        <p class={styles.Paragraph} style="width: 50vw">
          {'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'}
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar orientation="horizontal" class={styles.Scrollbar}>
      <ScrollArea.Thumb class={styles.Thumb} />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner class={styles.Corner} />
  </ScrollArea.Root>
}

```

### Both Directions

Enable scrolling in both horizontal and vertical directions.

**Example: both-directions**

```ripple
import { ScrollArea } from 'ark-ripple/scroll-area';
import styles from 'styles/scroll-area.module.css';

export component BothDirections() {
  <ScrollArea.Root class={styles.Root}>
    <ScrollArea.Viewport class={styles.Viewport}>
      <ScrollArea.Content class={styles.Content}>
        <p class={styles.Paragraph} style="width: 50vw">
          {'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar orientation="vertical" class={styles.Scrollbar}>
      <ScrollArea.Thumb class={styles.Thumb} />
    </ScrollArea.Scrollbar>
    <ScrollArea.Scrollbar orientation="horizontal" class={styles.Scrollbar}>
      <ScrollArea.Thumb class={styles.Thumb} />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner class={styles.Corner} />
  </ScrollArea.Root>
}

```

### Nested

Scroll areas can be nested within each other for complex layouts.

**Example: nested**

```ripple
import { ScrollArea } from 'ark-ripple/scroll-area';
import styles from 'styles/scroll-area.module.css';

export component Nested() {
  <ScrollArea.Root class={styles.Root} style="height: 12rem">
    <ScrollArea.Viewport class={styles.Viewport}>
      <ScrollArea.Content class={styles.Content}>
        <p class={styles.Paragraph}>
          {'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.'}
        </p>
        <ScrollArea.Root class={styles.Root} style="height: 8rem; width: 100%">
          <ScrollArea.Viewport class={styles.Viewport}>
            <ScrollArea.Content class={styles.Content}>
              <p class={styles.Paragraph}>
                {'This is a nested scroll area. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}
              </p>
            </ScrollArea.Content>
          </ScrollArea.Viewport>
          <ScrollArea.Scrollbar orientation="vertical" class={styles.Scrollbar}>
            <ScrollArea.Thumb class={styles.Thumb} />
          </ScrollArea.Scrollbar>
          <ScrollArea.Corner class={styles.Corner} />
        </ScrollArea.Root>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar orientation="vertical" class={styles.Scrollbar}>
      <ScrollArea.Thumb class={styles.Thumb} />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner class={styles.Corner} />
  </ScrollArea.Root>
}

```

## API Reference

### Props

**Component API Reference**

**Root Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `ids` | `Partial<{ root: string; viewport: string; content: string; scrollbar: string; thumb: string }>` | No | The ids of the scroll area elements |


**Root Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | root |
| `[data-overflow-x]` | Present when the content overflows the x-axis |
| `[data-overflow-y]` | Present when the content overflows the y-axis |


**Root CSS Variables:**

| Variable | Description |
|----------|-------------|
| `--corner-width` | The width of the Root |
| `--corner-height` | The height of the Root |
| `--thumb-width` | The width of the slider thumb |
| `--thumb-height` | The height of the slider thumb |


**Content Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |


**Content Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | content |
| `[data-overflow-x]` | Present when the content overflows the x-axis |
| `[data-overflow-y]` | Present when the content overflows the y-axis |


**Corner Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |


**Corner Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | corner |
| `[data-hover]` | Present when hovered |
| `[data-state]` | "hidden" | "visible" |
| `[data-overflow-x]` | Present when the content overflows the x-axis |
| `[data-overflow-y]` | Present when the content overflows the y-axis |


**RootProvider Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `value` | `UseScrollAreaReturn` | Yes |  |
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |


**Scrollbar Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |
| `orientation` | `Orientation` | No |  |


**Scrollbar Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | scrollbar |
| `[data-orientation]` | The orientation of the scrollbar |
| `[data-scrolling]` | Present when scrolling |
| `[data-hover]` | Present when hovered |
| `[data-dragging]` | Present when in the dragging state |
| `[data-overflow-x]` | Present when the content overflows the x-axis |
| `[data-overflow-y]` | Present when the content overflows the y-axis |


**Thumb Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |


**Thumb Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | thumb |
| `[data-orientation]` | The orientation of the thumb |
| `[data-hover]` | Present when hovered |
| `[data-dragging]` | Present when in the dragging state |


**Viewport Props:**

| Prop | Type | Required | Description |
|------|------|----------|-------------|
| `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. |


**Viewport Data Attributes:**

| Attribute | Value |
|-----------|-------|
| `[data-scope]` | scroll-area |
| `[data-part]` | viewport |
| `[data-at-top]` | Present when scrolled to the top edge |
| `[data-at-bottom]` | Present when scrolled to the bottom edge |
| `[data-at-left]` | Present when scrolled to the left edge |
| `[data-at-right]` | Present when scrolled to the right edge |
| `[data-overflow-x]` | Present when the content overflows the x-axis |
| `[data-overflow-y]` | Present when the content overflows the y-axis |


**Viewport CSS Variables:**

| Variable | Description |
|----------|-------------|
| `--scroll-area-overflow-x-start` | The distance from the horizontal start edge in pixels |
| `--scroll-area-overflow-x-end` | The distance from the horizontal end edge in pixels |
| `--scroll-area-overflow-y-start` | The distance from the vertical start edge in pixels |
| `--scroll-area-overflow-y-end` | The distance from the vertical end edge in pixels |


### Context

**API:**

| Property | Type | Description |
|----------|------|-------------|
| `isAtTop` | `boolean` | Whether the scroll area is at the top |
| `isAtBottom` | `boolean` | Whether the scroll area is at the bottom |
| `isAtLeft` | `boolean` | Whether the scroll area is at the left |
| `isAtRight` | `boolean` | Whether the scroll area is at the right |
| `hasOverflowX` | `boolean` | Whether the scroll area has horizontal overflow |
| `hasOverflowY` | `boolean` | Whether the scroll area has vertical overflow |
| `getScrollProgress` | `() => Point` | Get the scroll progress as values between 0 and 1 |
| `scrollToEdge` | `(details: ScrollToEdgeDetails) => void` | Scroll to the edge of the scroll area |
| `scrollTo` | `(details: ScrollToDetails) => void` | Scroll to specific coordinates |
| `getScrollbarState` | `(props: ScrollbarProps) => ScrollbarState` | Returns the state of the scrollbar |
