Skip to content
All components
Data display

Scroll area

Contain content in a bounded region that scrolls natively, with consistent styled scrollbars and a keyboard-focusable viewport.

A scroll container with a consistent custom scrollbar.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add scroll-area

Then import it from @/components/ui/scroll-area. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Horizontal strip

Scroll a single row of items sideways. A horizontal scrollbar is added explicitly and the named region can be scrolled with the keyboard. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

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

const tags = [
  "Design",
  "Research",
  "Engineering",
  "Marketing",
  "Support",
  "Finance",
  "Operations",
  "Legal",
  "Sales",
  "Recruiting",
]

export function ScrollAreaHorizontalStrip() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <ScrollArea role="region" aria-label="Filter by team" className="w-full max-w-xs rounded-12 border border-soft-200">
        <ul className="flex w-max gap-2 p-3">
          {tags.map((tag) => (
            <li
              key={tag}
              className="rounded-full border border-soft-200 px-3 py-1 text-label-sm whitespace-nowrap text-strong-950"
            >
              {tag}
            </li>
          ))}
        </ul>
        <ScrollBar orientation="horizontal" />
      </ScrollArea>
    </div>
  )
}

Both directions

Scroll wide and long content in both directions. Long log lines keep their format while the page itself does not scroll sideways. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

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

const logLines = Array.from(
  { length: 30 },
  (_, index) =>
    `12:${String(index).padStart(2, "0")}:04  worker-${(index % 3) + 1}  processed batch ${1040 + index} in ${180 + index * 7} ms, 0 retries, queue depth ${40 - index}`
)

export function ScrollAreaBothDirections() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <ScrollArea role="region" aria-label="Worker log" className="h-56 w-full rounded-12 border border-soft-200">
        <pre className="w-max p-3 font-mono text-paragraph-sm text-sub-600">
          {logLines.join("\n")}
        </pre>
        <ScrollBar orientation="horizontal" />
      </ScrollArea>
    </div>
  )
}

Always visible scrollbars

Keep the scrollbar visible to signal more content. type always shows the scrollbar even before the pointer enters the region. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

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

export function ScrollAreaAlwaysVisibleScrollbars() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <ScrollArea
        type="always"
        role="region"
        aria-label="Terms of service"
        className="h-48 w-full max-w-sm rounded-12 border border-soft-200"
      >
        <div className="flex flex-col gap-3 p-4 pe-5 text-paragraph-sm text-sub-600">
          <p className="text-label-sm text-strong-950">Terms of service</p>
          <p>These terms apply to every workspace created after 1 January 2026.</p>
          <p>You keep ownership of the content you upload. We process it only to provide the service.</p>
          <p>Either party may end the agreement with 30 days written notice.</p>
          <p>We notify workspace owners by email at least 14 days before these terms change.</p>
          <p>Questions about these terms can be sent from the help page.</p>
        </div>
      </ScrollArea>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

ScrollArea

Provide a bounded scroll region with styled scrollbars.

ScrollArea props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (17)
ScrollArea inherited props
PropTypeDefaultDescription
type("auto" | "always" | "hover" | "scroll") | undefined—Scrollbar visibility strategy defined by the ScrollArea primitive, not an HTML input type.
dir("ltr" | "rtl") | undefined—Reading direction used by the primitive. Keep it consistent with the surrounding content and Direction provider.
scrollHideDelaynumber | undefined—Delay before the primitive hides a scrollbar after scrolling or pointer interaction.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.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).

ScrollBar

The ScrollBar part of scroll-area. Use it with the complete source composition and preserve its required parent context.

ScrollBar props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (16)
ScrollBar inherited props
PropTypeDefaultDescription
forceMounttrue | undefined—Keep the primitive mounted for consumer-owned rendering or animation. Hidden content must remain inaccessible and unfocusable.
orientation("horizontal" | "vertical") | undefined"vertical"Horizontal or vertical layout/navigation axis as defined by this primitive.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.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).

Accessibility & usage

From registry/ui/scroll-area.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A fixed-height panel inside a larger layout: a list in a popover, a sidebar section, terms inside a dialog, a log.
  • A horizontal strip of chips or cards that should scroll sideways without making the page scroll.
  • Wide preformatted content (logs, code) that must keep its line format and scroll in both directions.

When not to use

  • The main page content; let the page scroll natively instead of nesting a scroll region.
  • A conversation that grows at the end and should follow new messages; use MessageScroller.
  • Short content that fits; an always-present scroll region adds a tab stop for nothing.
  • Wide tables; Table already includes its own focusable horizontal scroll wrapper.

Anatomy

ScrollArea
Radix root (relative) that sizes the region; type controls scrollbar visibility (hover by default, always, scroll or auto). Name it with role="region" and aria-label when it holds meaningful content.
Viewport
Internal native scroll container with tabIndex 0 and a visible focus style; your children render inside it. Not configurable through root props.
ScrollBar
Styled scrollbar and thumb. A vertical one is included; add <ScrollBar orientation="horizontal" /> as a child for sideways scrolling.
Corner
Fills the corner where both scrollbars meet.

Keyboard & interaction

  • Scrolling is native: wheel, trackpad, touch and the scrollbar thumb all work, and the browser's own scrolling stays intact.
  • The viewport is focusable so keyboard users can scroll with arrow keys, Page Up/Down, Home/End and Space; Tab then leaves the region.
  • Focus inside the content (links, buttons) scrolls the viewport to show the focused element.
  • Scrollbars appear on hover by default; type="always" keeps them visible as a cue that more content exists.
  • There is no controlled scroll position, disabled state or follow-new-content behavior.

Responsive behavior

  • Give the region a height that leaves room for the rest of the screen on small devices; prefer max-height over fixed height so short content does not leave gaps.
  • Horizontal regions let wide content scroll inside them while the page itself reflows at 320 CSS pixels (WCAG 1.4.10).
  • Avoid scroll regions in scroll regions on touch devices; nested scrolling is hard to control with one finger.
  • Overlay scrollbars are thin; on touch screens people swipe the content, so do not rely on dragging the thumb.

Content guidelines

  • Name the region by its content ('Terms of service', 'Worker log') so assistive technology announces what scrolls.
  • Show a visible cue that content continues: a partly cut item, a fade that does not cover controls, or an always-visible scrollbar.
  • Put the most important item first; people often do not scroll small regions.
  • Keep lines in logs and code intact and let the region scroll horizontally rather than wrapping them unpredictably.

Alternatives

  • Message scroller — Follows new content at the end while respecting a reader who scrolled up.
  • Table — Tabular data, which already scrolls horizontally inside its own wrapper.
  • Carousel — Discrete slides with previous and next controls.

Resources