Scroll Area

A scrollable container with custom styled scrollbars.

Import

import { ScrollArea } from '@matix/components/scroll-area';

Usage

Horizontal Scroll

Use a horizontal scrollbar for wide content.

import * as stylex from '@stylexjs/stylex';

const custom = stylex.create({
  root: { width: 400 },
  track: { display: 'flex', gap: 16, padding: 16, width: 800 },
  item: {
    flexShrink: 0,
    width: 120,
    height: 80,
    borderRadius: 8,
    backgroundColor: '#e2e8f0',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    fontSize: 14,
  },
});

<ScrollArea.Root sx={custom.root}>
  <ScrollArea.Viewport>
    <div {...stylex.props(custom.track)}>
      {Array.from({ length: 10 }, (_, i) => (
        <div key={i} {...stylex.props(custom.item)}>
          Item {i + 1}
        </div>
      ))}
    </div>
  </ScrollArea.Viewport>
  <ScrollArea.Scrollbar orientation="horizontal">
    <ScrollArea.Thumb />
  </ScrollArea.Scrollbar>
</ScrollArea.Root>;

Both Directions

Combine vertical and horizontal scrollbars with a corner piece.

import * as stylex from '@stylexjs/stylex';

const custom = stylex.create({
  root: { height: 200, width: 300 },
  content: { width: 600, padding: 16 },
});

<ScrollArea.Root sx={custom.root}>
  <ScrollArea.Viewport>
    <div {...stylex.props(custom.content)}>
      <p>This content is both tall and wide, requiring scrollbars in both directions.</p>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
        labore et dolore magna aliqua.
      </p>
      <p>
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
        commodo consequat.
      </p>
      <p>
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
        pariatur.
      </p>
    </div>
  </ScrollArea.Viewport>
  <ScrollArea.Scrollbar orientation="vertical">
    <ScrollArea.Thumb />
  </ScrollArea.Scrollbar>
  <ScrollArea.Scrollbar orientation="horizontal">
    <ScrollArea.Thumb />
  </ScrollArea.Scrollbar>
  <ScrollArea.Corner />
</ScrollArea.Root>;

Custom Styles

Use the sx prop on any sub-component to override styles.

import * as stylex from '@stylexjs/stylex';

const custom = stylex.create({
  root: { height: 160, border: '1px solid #e2e8f0', borderRadius: 8 },
  content: { padding: 16 },
  scrollbar: { backgroundColor: '#f1f5f9' },
  thumb: { backgroundColor: '#94a3b8', borderRadius: 4 },
});

<ScrollArea.Root sx={custom.root}>
  <ScrollArea.Viewport>
    <div {...stylex.props(custom.content)}>
      <p>Custom scrollbar styling using sx props.</p>
      <p>
        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.
      </p>
      <p>
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
        pariatur.
      </p>
    </div>
  </ScrollArea.Viewport>
  <ScrollArea.Scrollbar orientation="vertical" sx={custom.scrollbar}>
    <ScrollArea.Thumb sx={custom.thumb} />
  </ScrollArea.Scrollbar>
</ScrollArea.Root>;

Server Components

ScrollArea is a client component. A Server Component cannot read a property of a client component, so ScrollArea.Root is undefined there. In a Server Component, import the named parts. Each ScrollArea.<Part> is also exported as ScrollArea<Part>.

import {
  ScrollAreaRoot,
  ScrollAreaViewport,
  ScrollAreaScrollbar,
  ScrollAreaThumb,
  ScrollAreaCorner,
} from '@matix/components/scroll-area';

In a client component, both forms work.

API Reference

ComponentPropTypeDefaultDescription
ScrollArea.RootsxStyleXStyles—StyleX style override
ScrollArea.ViewportsxStyleXStyles—StyleX style override
ScrollArea.Scrollbarorientation'vertical' | 'horizontal''vertical'Scrollbar direction
ScrollArea.ScrollbarsxStyleXStyles—StyleX style override
ScrollArea.ThumbsxStyleXStyles—StyleX style override
ScrollArea.CornersxStyleXStyles—StyleX style override

All other props on each sub-component are forwarded to the underlying Base UI element.

Accessibility

  • Built on Base UI ScrollArea — provides custom scrollbar styling while preserving native scroll behavior.
  • Content remains scrollable via mouse wheel, trackpad, and touch gestures.
  • Scrollbar thumb is draggable for precise scroll positioning.
  • Does not interfere with screen reader content — the underlying scrollable region is a standard overflow container.
  • All scrollbar visuals are purely decorative and do not add extra ARIA roles.

Keyboard

KeyAction
ArrowDownScrolls content down (when viewport is focused)
ArrowUpScrolls content up (when viewport is focused)
ArrowRightScrolls content right (horizontal mode)
ArrowLeftScrolls content left (horizontal mode)
Page DownScrolls one page down
Page UpScrolls one page up
HomeScrolls to the top
EndScrolls to the bottom