Theme

Customize appearance

Components

Scroll Area

Contain overflowing content within a styled scroll region.

View component source ↗

Preview

A minimal example to get started.

Installation

Install this component and its dependencies in a project initialized with shadcn.

pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/scroll-area.json

Usage

This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.

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

export default function Example() {
  return (
    <ScrollArea className="h-48 w-64 rounded-lg border">
      <div className="p-4">
        {Array.from({ length: 20 }, (_, index) => (
          <p className="border-b py-2 text-sm" key={index}>
            Project {index + 1}
          </p>
        ))}
      </div>
    </ScrollArea>
  );
}

API reference

Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.

ScrollArea
ScrollArea properties
PropTypeDefaultDescription
overflowEdgeThreshold
number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }> | undefi…
number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }> | undefined
0The threshold in pixels that must be passed before the overflow edge attributes are applied. Accepts a single number for all edges or an object to configure them individually.
ref
React.Ref<HTMLDivElement> | undefined
React.Ref<HTMLDivElement> | undefined
—Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the control receives focus.
onBlur
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the control loses focus.
onChange
((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined
((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined
—Called when a key is pressed while this element is focused.
onClick
((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined
((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined
—Called when the element is activated.
className
string | ((state: ScrollAreaRootState) => string | undefined) | undefined
string | ((state: ScrollAreaRootState) => string | undefined) | undefined
—CSS class applied to the element, or a function that returns a class based on the component's state.
render
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ScrollAreaRootState> | undefined
—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
style
React.CSSProperties | ((state: ScrollAreaRootState) => React.CSSProperties | undefined) | …
React.CSSProperties | ((state: ScrollAreaRootState) => React.CSSProperties | undefined) | undefined
—Style applied to the element, or a function that returns a style object based on the component's state.
ScrollBar
ScrollBar properties
PropTypeDefaultDescription
orientation
"horizontal" | "vertical" | undefined
"horizontal" | "vertical" | undefined
"vertical"Whether the scrollbar controls vertical or horizontal scroll.
keepMounted
boolean | undefined
boolean | undefined
falseWhether to keep the HTML element in the DOM when the viewport isn't scrollable.
ref
React.Ref<HTMLDivElement> | undefined
React.Ref<HTMLDivElement> | undefined
—Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the control receives focus.
onBlur
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the control loses focus.
onChange
((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined
((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined
((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined
—Called when a key is pressed while this element is focused.
onClick
((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined
((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined
—Called when the element is activated.
className
string | ((state: ScrollAreaScrollbarState) => string | undefined) | undefined
string | ((state: ScrollAreaScrollbarState) => string | undefined) | undefined
—CSS class applied to the element, or a function that returns a class based on the component's state.
render
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ScrollAreaScrollbarState> | undefined
—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
style
React.CSSProperties | ((state: ScrollAreaScrollbarState) => React.CSSProperties | undefine…
React.CSSProperties | ((state: ScrollAreaScrollbarState) => React.CSSProperties | undefined) | undefined
—Style applied to the element, or a function that returns a style object based on the component's state.

Usage notes

Set a bounded height or width to enable scrolling. Keep the content readable and avoid nesting unnecessary scroll regions.