How it works
Rows and headers have fixed heights, so the offset of every row is computed once and the window is found with a binary search on each scroll frame; nothing is measured and the scrollbar never jumps. Rows are placed with translateY inside one spacer, and the scroller uses contain: strict, so scrolling 10,000 rows renders about twenty. The pinned header is a separate layer drawn over the top edge and pushed up by the next header.
Use it for
- Directories, logs, transactions or any list of thousands of uniform rows.
- Pickers that must let people scroll the whole set, not just search it.
Look elsewhere when
- Rows of very different heights: use paging or an infinite list.
- Under a few hundred rows: a plain list is simpler and supports find-in-page.
Usage
import { useState } from 'react'
import { VirtualList } from './VirtualList.jsx'
export function Directory({ people }) {
const [picked, setPicked] = useState(null)
return (
<VirtualList
label="Contacts"
items={people}
getKey={(p) => p.id}
getGroup={(p) => p.name[0]}
rowHeight={56}
height={400}
value={picked}
onSelect={(p) => setPicked(p.id)}
renderItem={(p) => <span>{p.name}</span>}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
items | T[] | — | All rows, already sorted so that groups are contiguous. |
renderItem | (item, index, { selected, active }) => ReactNode | — | Renders one row at rowHeight. |
getKey | (item, index) => Key | item.id ?? index | Stable key; also what value compares against. |
getGroup | (item, index) => string | — | Group label; a header is inserted wherever it changes and pinned while its rows are in view. |
rowHeight | number | 52 | Fixed height of every row in px. |
headerHeight | number | 32 | Fixed height of group headers in px. |
height | number | 400 | Height of the scroll area in px. |
overscan | number | 6 | Extra rows rendered above and below the view, so fast scrolling never shows gaps. |
value | Key | — | Key of the selected row. |
onSelect | (item, index) => void | — | Called on click, Enter or Space. |
onRangeChange | ({ first, last, rendered }) => void | — | Called when the rendered window changes; useful for prefetching. |
label | string | — | Accessible name of the listbox. |
Accessibility
- The scroller is a focusable listbox; rows are options with aria-setsize and aria-posinset, so position is announced as "5,231 of 10,000".
- Focus stays on the listbox and the active row is aria-activedescendant; that row is always kept in the DOM, even off screen.
- Keyboard: Up / Down, PageUp / PageDown, Home / End move and scroll the row into view below the pinned header; Enter or Space selects.
- Group headers are visual only (the pinned copy is aria-hidden). Browser find-in-page cannot see rows that are not rendered; offer search.
Motion
Scrolling is native. The pinned header gains a hairline over 200ms once the list leaves the top; row hover and active fills change in 120ms.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
VirtualList.jsxvirtual-list.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





