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
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
ScrollArea.Root | sx | StyleXStyles | — | StyleX style override |
ScrollArea.Viewport | sx | StyleXStyles | — | StyleX style override |
ScrollArea.Scrollbar | orientation | 'vertical' | 'horizontal' | 'vertical' | Scrollbar direction |
ScrollArea.Scrollbar | sx | StyleXStyles | — | StyleX style override |
ScrollArea.Thumb | sx | StyleXStyles | — | StyleX style override |
ScrollArea.Corner | sx | StyleXStyles | — | 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
| Key | Action |
|---|---|
ArrowDown | Scrolls content down (when viewport is focused) |
ArrowUp | Scrolls content up (when viewport is focused) |
ArrowRight | Scrolls content right (horizontal mode) |
ArrowLeft | Scrolls content left (horizontal mode) |
Page Down | Scrolls one page down |
Page Up | Scrolls one page up |
Home | Scrolls to the top |
End | Scrolls to the bottom |