# Scroll area: Start at the bottom

> `viewportRef` gives you the scrolling element. Set its `scrollTop` to start a chat at the latest message, so only the top edge fades.

Example: https://hextaui.com/docs/scroll-area/examples/chat
Component docs: https://hextaui.com/docs/scroll-area.md

## Add this example

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

This adds `components/examples/scroll-area/chat.tsx` with the Scroll area component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/scroll-area/chat.tsx"
"use client"

import * as React from "react"

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

export function ScrollAreaChat() {
  const viewportRef = React.useRef<HTMLDivElement>(null)

  React.useLayoutEffect(() => {
    const viewport = viewportRef.current
    if (viewport) {
      viewport.scrollTop = viewport.scrollHeight
    }
  }, [])

  return (
    <ScrollArea
      viewportRef={viewportRef}
      aria-label="Messages"
      className="h-56 w-full max-w-sm rounded-lg border"
    >
      <div className="flex flex-col gap-2 p-3 text-sm">
        {Array.from({ length: 24 }, (_, index) => (
          <p
            key={index}
            className={
              index % 3 === 0
                ? "self-end rounded-lg bg-primary px-3 py-2 text-primary-foreground"
                : "self-start rounded-lg bg-muted px-3 py-2"
            }
          >
            Message {index + 1}
          </p>
        ))}
      </div>
    </ScrollArea>
  )
}
```

## Props in this example

### ScrollArea

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `viewportRef` | `Ref<HTMLDivElement>` | – | The element that scrolls. |
| `className` | `string \| (state) => string` | – |  |

## More Scroll area examples

- [Peek](https://hextaui.com/docs/scroll-area/examples/peek.md)
- [Text](https://hextaui.com/docs/scroll-area/examples/text.md)
- [Horizontal](https://hextaui.com/docs/scroll-area/examples/horizontal.md)
- [Both axes](https://hextaui.com/docs/scroll-area/examples/both.md)
- [Dynamic content](https://hextaui.com/docs/scroll-area/examples/dynamic.md)
- [On a colored surface](https://hextaui.com/docs/scroll-area/examples/colored-surface.md)
- [Inside a sheet](https://hextaui.com/docs/scroll-area/examples/sheet.md)
- [Without fade](https://hextaui.com/docs/scroll-area/examples/without-fade.md)
- [Right to left](https://hextaui.com/docs/scroll-area/examples/rtl.md)
