Course contentsShow
← React
Lesson 1285 of 2,39632. Lists and Keys Deep DiveFree lesson

Accessibility Considerations

Address a11y challenges: screen readers, keyboard navigation, and aria attributes with virtualized content.

Accessibility Considerations

You'll learn how to make virtualized lists usable for everyone, especially those relying on screen readers and keyboards.

The Virtualization Accessibility Challenge

When you virtualize a list (rendering only visible items), you create serious accessibility problems. Screen readers expect the entire list to exist in the DOM so they can announce the total count and allow navigation through all items. But virtualization removes most items from the DOM entirely—they literally don't exist for assistive technology to read.

Think of it like this: A screen reader user approaches a library with 10,000 books, but the building only shows them 20 books at a time and hides the rest. They have no idea there are 10,000 books or how to navigate to book #5,432.

Key Accessibility Solutions

Total Count Announcement: Use aria-label on the container to announce the full list size:

<div 
  role="list"
  aria-label={`${allItems.length} items`}
  style={{ height: '400px', overflow: 'auto' }}
>

Individual Item Semantics: Each virtual item needs proper ARIA attributes:

<div 
  role="listitem"
  aria-setsize={allItems.length}
  aria-posinset={virtualItem.index + 1}
>

Keyboard Navigation: Ensure users can Tab through focusable elements and use Arrow keys to scroll. Monitor onKeyDown events and programmatically scroll the virtualizer to the next item.

Focus Management: When items mount/unmount during scrolling, preserve focus context so keyboard users don't lose their place.

Alternative Patterns: For critical accessibility contexts, consider "Load More" buttons or pagination instead of virtualization—they're more accessible by default.

Key Takeaway: Virtualization trades DOM presence for performance; restore accessibility with ARIA attributes announcing total count, position, and proper keyboard navigation handling.