Scroll Area
Layout
Utility
Scrollable container with customizable scrollbar styling. Supports vertical, horizontal, and bidirectional scrolling with configurable visibility options.
Preview
Vertical scroll with custom styled scrollbars
Horizontal Scroll
Scroll horizontally through content
Bidirectional
Scroll in both vertical and horizontal directions
Props
ScrollArea component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
maxHeight | string | number | '400px' | Maximum height of the scroll area |
scrollbarVisibility | 'auto' | 'always' | 'hover' | 'auto' | When to show the scrollbar |
orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | Scroll direction(s) enabled |
className | string | — | Additional CSS classes |
...props | HTMLAttributes<HTMLDivElement> | — | All standard div attributes are supported |
Usage
Import and implementation example
import { ScrollArea } from '@/components/ui/scroll-area'
export default function Example() {
return (
<>
{/* Vertical scroll */}
<ScrollArea maxHeight="400px">
<div>Long content...</div>
</ScrollArea>
{/* Horizontal scroll */}
<ScrollArea orientation="horizontal">
<div className="flex gap-4">
{items.map(item => <Card key={item.id} />)}
</div>
</ScrollArea>
{/* Both directions */}
<ScrollArea orientation="both" maxHeight="300px">
<div className="w-[1500px]">Wide and tall content</div>
</ScrollArea>
{/* Always visible scrollbar */}
<ScrollArea scrollbarVisibility="always" maxHeight="300px">
<div>Content with visible scrollbar</div>
</ScrollArea>
{/* Show on hover only */}
<ScrollArea scrollbarVisibility="hover" maxHeight="300px">
<div>Scrollbar appears on hover</div>
</ScrollArea>
</>
)
}Features
Built-in functionality
- Custom scrollbars: Styled scrollbars matching design system
- Three orientations: Vertical, horizontal, or both directions
- Visibility options: Auto, always visible, or show on hover
- Configurable max height: Set maximum height as string or number
- Hover effects: Scrollbar thumb highlights on hover
- Forward ref: Supports ref forwarding for DOM access
Accessibility
Keyboard and screen reader support
ARIA Attributes
tabindex="0" for keyboard focusrole="region" with scroll capabilitiesKeyboard Navigation
| Key | Action |
|---|---|
| Arrow Keys | Scroll content when focused |
| Page Up/Down | Scroll by page |
| Home/End | Scroll to start/end |
Notes
- Scrollable region is focusable for keyboard navigation
- Content inside remains accessible
- Custom scrollbars do not interfere with assistive technology