Scroll Area

Augments native scroll functionality for custom, cross-browser styling.

Features

  • Scrollbar sits on top of the scrollable content, taking up no space.
  • Scrolling is native; no underlying position movements via CSS transformations.
  • Shims pointer behaviors only when interacting with the controls, so keyboard controls are unaffected.
  • Supports RTL

Install the component from your command line.

npm install @radix-ui/react-scroll-area

Import the components and piece the parts together.

import * as ScrollArea from '@radix-ui/react-scroll-area';
export default () => (
<ScrollArea.Root>
<ScrollArea.Viewport />
<ScrollArea.Scrollbar orientation="horizontal">
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Scrollbar orientation="vertical">
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>
);

Create your styled scroll area component from the primitive parts.

import { styled } from 'path-to/stitches.config';
import * as ScrollArea from '@radix-ui/react-scroll-area';
const SCROLLBAR_SIZE = 8;
const StyledScrollArea = styled(ScrollArea.Root, {
width: '100%',
height: '100%',
});
const StyledViewport = styled(ScrollArea.Viewport, {
width: '100%',
height: '100%',
});
const StyledScrollbar = styled(ScrollArea.Scrollbar, {
display: 'flex',
width: SCROLLBAR_SIZE,
padding: 2,
background: 'rgba(0, 0, 0, 0.3)',
'&:hover': {
background: 'rgba(0, 0, 0, 0.5)',
},
transition: 'background 160ms ease-out',
});
const StyledThumb = styled(ScrollArea.Thumb, {
flex: 1,
background: 'black',
borderRadius: SCROLLBAR_SIZE,
});
export default () => (
<div style={{ height: 250 }}>
<StyledScrollArea>
<StyledViewport>
<div style={{ height: 1000, backgroundImage: 'repeating-linear-gradient(0deg, dodgerblue, dodgerblue 10px, transparent 10px, transparent 20px)', }} />
</StyledViewport>
<StyledScrollbar>
<StyledThumb />
</StyledScrollbar>
</StyledScrollArea>
</div>
);

Contains all the parts of a scroll area.

PropTypeDefault
asenumdiv
typeenum"hover"
scrollHideDelaynumber600
direnumNo default value

The viewport area of the scroll area.

PropTypeDefault
asenumdiv

The horizontal scrollbar.

PropTypeDefault
asenumdiv
forceMountbooleanNo default value
orientationenumvertical

The thumb to be used in ScrollArea.Scrollbar.

PropTypeDefault
asenumdiv

The corner where both vertical and horizontal scrollbars meet.

PropTypeDefault
asenumdiv

In most cases, it's best to rely on native scrolling and work with the customization options available in CSS. When that isn't enough, ScrollArea provides additional customizability while maintaining the browser's native scroll behavior (as well as accessibiliy features, like keyboard scrolling).

Scrolling via keyboard is supported by default because the component relies on native scrolling. Specific keyboard interactions may differ between platforms, so we do not specify them here or add specific event listeners to handle scrolling via key events.