← Components

Utilities

Scroll area

A quiet scrollbar that fades in while scrolling and widens on hover; edges fade where there's more.

Examples and variants

Basic

Scroll the list.

Example
function ScrollAreaBasic() {
  return (
    <ScrollArea className="h-40 w-full max-w-xs rounded-(--shape-md) bg-canvas shadow-1">
      <div className="flex flex-col gap-1 p-3 text-sm">
        {Array.from({ length: 16 }, (_, index) => (
          <span key={index}>Release note {16 - index}</span>
        ))}
      </div>
    </ScrollArea>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/scroll-area.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install @base-ui/react cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/scroll-area.tsxscroll-area
      components/ui/scroll-area.tsx
      "use client"
      
      import * as React from "react"
      import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area"
      import { cn } from "cn"
      
      /*
        Scroll Area: a scrollable panel with a quiet scrollbar. The thumb fades in
        while scrolling and widens on hover; a soft fade appears at an edge when
        there's more content past it.
      */
      function ScrollArea({ className, children, ...props }: ScrollAreaPrimitive.Root.Props) {
        return (
          <ScrollAreaPrimitive.Root data-slot="scroll-area" className={cn("scroll-area relative min-h-0", className)} {...props}>
            <ScrollAreaPrimitive.Viewport
              data-slot="scroll-area-viewport"
              className="scroll-area-viewport size-full rounded-[inherit] outline-none focus-visible:shadow-(--focus-ring)"
            >
              <ScrollAreaPrimitive.Content>{children}</ScrollAreaPrimitive.Content>
            </ScrollAreaPrimitive.Viewport>
            <ScrollBar />
            <ScrollAreaPrimitive.Corner />
          </ScrollAreaPrimitive.Root>
        )
      }
      
      function ScrollBar({ className, orientation = "vertical", ...props }: ScrollAreaPrimitive.Scrollbar.Props) {
        return (
          <ScrollAreaPrimitive.Scrollbar
            data-slot="scroll-area-scrollbar"
            orientation={orientation}
            className={cn(
              "scroll-area-bar flex touch-none p-0.5 select-none",
              orientation === "vertical" ? "h-full w-2.5" : "h-2.5 flex-col",
              className
            )}
            {...props}
          >
            <ScrollAreaPrimitive.Thumb data-slot="scroll-area-thumb" className="scroll-area-thumb relative flex-1 rounded-(--radius-pill) bg-(--color-fg-subtle)" />
          </ScrollAreaPrimitive.Scrollbar>
        )
      }
      
      export { ScrollArea, ScrollBar }
      

Imports

What the examples on this page import:

Imports
import { InfoIcon } from "lucide-react"
import { Alert, AlertTitle } from "@/components/ui/alert"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { Button } from "@/components/ui/button"
import { Collapsible, CollapsibleContent, CollapsibleLabel, CollapsibleTrigger } from "@/components/ui/collapsible"
import { DirectionProvider } from "@/components/ui/direction"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Heading, Text } from "@/components/ui/typography"

Anatomy

  1. 1Viewport · Edge fade mask.
  2. 2Scrollbar and thumb · Thin; widens on hover.

Props

PropTypeDefaultDescription
classNamestring—Give it a height.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

This utility has no component tokens; it uses semantic tokens directly.

TokenPoints toLightDark

Motion

TriggerWhat happensTokens
Scroll / hoverThumb fades in, then out; widens on hover.--duration-medium, --duration-fast

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Keyboard scrolling works; the viewport is focusable.

Code

components/ui/scroll-area.tsx
"use client"

import * as React from "react"
import { ScrollArea as ScrollAreaPrimitive } from "@base-ui/react/scroll-area"
import { cn } from "cn"

/*
  Scroll Area: a scrollable panel with a quiet scrollbar. The thumb fades in
  while scrolling and widens on hover; a soft fade appears at an edge when
  there's more content past it.
*/
function ScrollArea({ className, children, ...props }: ScrollAreaPrimitive.Root.Props) {
  return (
    <ScrollAreaPrimitive.Root data-slot="scroll-area" className={cn("scroll-area relative min-h-0", className)} {...props}>
      <ScrollAreaPrimitive.Viewport
        data-slot="scroll-area-viewport"
        className="scroll-area-viewport size-full rounded-[inherit] outline-none focus-visible:shadow-(--focus-ring)"
      >
        <ScrollAreaPrimitive.Content>{children}</ScrollAreaPrimitive.Content>
      </ScrollAreaPrimitive.Viewport>
      <ScrollBar />
      <ScrollAreaPrimitive.Corner />
    </ScrollAreaPrimitive.Root>
  )
}

function ScrollBar({ className, orientation = "vertical", ...props }: ScrollAreaPrimitive.Scrollbar.Props) {
  return (
    <ScrollAreaPrimitive.Scrollbar
      data-slot="scroll-area-scrollbar"
      orientation={orientation}
      className={cn(
        "scroll-area-bar flex touch-none p-0.5 select-none",
        orientation === "vertical" ? "h-full w-2.5" : "h-2.5 flex-col",
        className
      )}
      {...props}
    >
      <ScrollAreaPrimitive.Thumb data-slot="scroll-area-thumb" className="scroll-area-thumb relative flex-1 rounded-(--radius-pill) bg-(--color-fg-subtle)" />
    </ScrollAreaPrimitive.Scrollbar>
  )
}

export { ScrollArea, ScrollBar }