Course contentsShow
← Web Development
Lesson 1097 of 2,98219. Keyboard Navigation and FocusFree lesson

Focus Management in Infinite Scroll

Maintaining focus context and keyboard navigation in dynamically loading content like infinite scroll lists.

Focus Management in Infinite Scroll

What you'll learn: How to maintain keyboard navigation context when new content dynamically loads at the bottom of a scrolling list.

The Challenge

Infinite scroll creates a tricky accessibility problem. When users navigate through a list with arrow keys or Tab, and new items suddenly load at the bottom, their focus can get lost or confused. Screen reader users might not realize new content appeared, and keyboard users can lose their place in the list.

Think of it like reading a book where someone keeps adding pages while you're mid-sentence—you need clear signals about what just happened and where you were.

Core Strategies

Announce New Content

Use aria-live regions to inform screen reader users when new items load:

<div aria-live="polite" aria-atomic="true" class="sr-only">
  Loaded 20 more items
</div>

Preserve Focus Context

When new items load, don't move focus automatically. The user should remain on their current item. Use aria-setsize and aria-posinset to help users understand their position:

<div role="listitem" aria-setsize="100" aria-posinset="15">
  Item 15 of 100
</div>

Loading State Management

Use tabindex="-1" and aria-busy="true" on the container while loading to prevent navigation into incomplete content. Restore normal focus order once loading completes.

Restore Focus After Removal

If implementing "load more" buttons instead of automatic scroll, move focus to the first new item after the button is clicked and removed (applying your "Moving Focus After Element Removal" knowledge).

Key Takeaway: In infinite scroll, maintain focus on the user's current position, announce new content arrivals through live regions, and provide clear position indicators—never hijack focus or surprise keyboard users with unexpected content changes.