30% offEnding soon
FSD-014Frontend system design Premium

Design a Carousel for Touch, Mouse, Keyboard, and TV

Design a carousel with one navigation model across gestures, buttons, keyboards, and TV remotes, plus safe looping, media loading, and motion control.

Intermediate 52 min read

Build one logical navigator, then adapt touch, mouse, keyboard, buttons, and TV remotes into the same commands. The renderer may scroll, snap, or normalize a loop, but logical slide identity, focus, and pause state stay stable.

A carousel is often introduced as an array plus a current index. That model works until a finger changes direction mid-swipe, a TV remote moves focus into the next card, an image decodes late, or an autoplay timer fires while the user is reading. The difficult part is not moving pixels. It is deciding who owns navigation and when a movement becomes committed.

Start with a logical sequence

Keep slide records keyed by stable IDs. Store the logical active ID, the last settled direction, autoplay pause reasons, and any pending command outside rendered slide elements. Treat scroll offset as presentation evidence, not product truth.

Every input adapter should emit a small command such as previous, next, goTo(id), pause(reason), or resume(reason). This keeps a swipe, a click, an ArrowRight press, and a TV remote action from developing different wrap, loading, and analytics behavior.

The public interview prompt

Design a reusable carousel for editorial stories, products, or media cards. It must work with touch, mouse, keyboard, and TV remotes. Explain:

  • stable slide IDs, active identity, settled geometry, and navigation commands;
  • native scroll snapping versus custom pointer physics;
  • gesture intent, velocity, distance, cancellation, and nested page scrolling;
  • previous, next, picker, keyboard, and spatial focus behavior;
  • autoplay ownership, pause reasons, visibility, and reduced motion;
  • finite navigation, optional looping, sentinel clones, and normalization;
  • responsive image sources, decode timing, lazy loading, prefetch, and failure states;
  • focus isolation, announcements, slide naming, and hidden content;
  • resize, orientation change, restoration, deep links, analytics, and experiments;
  • large catalogs, bounded rendering, performance budgets, testing, and rollout.

Assume a page can show several carousels, each with 8 to 200 slides. A TV layout shows multiple focusable cards per screen. Mobile users may begin a vertical page scroll over the carousel. Network quality varies, and some slides contain video. These are interview assumptions, not measured product facts.

What the premium solution covers

The full solution defines the state machine, command boundary, native and custom gesture options, settled-slide detection, TV focus rules, autoplay arbitration, media priority, accessible semantics, safe loop normalization, rendering limits, observability, tests, and rollout plan.

Original media follows one command through four input adapters, opens the loop sentinel model, shows the media priority window, and maps focus ownership. Two deterministic labs let readers test gesture thresholds and autoplay pause arbitration.

Premium solution

Continue with the complete system design

Unlock the architecture, state machine, API contracts, original diagrams, positioning model, accessibility decisions, performance budgets, testing plan, rollout strategy, scoring rubric, and interview walkthrough.

  • Detailed, beginner-friendly explanation
  • Production failure modes and trade-offs
  • Mobile-friendly architecture diagrams
  • Senior and staff-level interview signals
Unlock Premium

Frequently asked questions

Should a web carousel use native scrolling or custom drag physics?
Prefer native horizontal scrolling with CSS scroll snap when the layout permits it. It preserves platform touch behavior and browser scrolling. Use custom pointer physics only when the product requires interaction that native scrolling cannot express, and then handle pointer cancellation and capture explicitly.
When should the active slide change?
Change it after the viewport settles on a snap target or after a programmatic navigation command is accepted. Do not rewrite active state on every scroll event because intermediate geometry is noisy and may reverse during a gesture.
How should autoplay pause?
Pause when focus enters, the pointer hovers where relevant, the page becomes hidden, reduced motion is requested, media is playing, or the user explicitly pauses. Explicit pause should remain sticky and autoplay should not restart merely because focus leaves.
How can an infinite carousel remain accessible?
Keep a finite logical slide set. If cloned sentinel slides are used for visual continuity, hide them from accessibility APIs and remove their descendants from focus. Normalize from a sentinel to its real counterpart without animation while preserving the logical active ID.
How should a TV remote navigate a carousel?
Treat directional remote input as a focus-navigation adapter. Left and right move within the carousel when that is the declared focus boundary. Up and down leave toward predictable neighboring regions. Keep the focused control or card visible before moving focus.
How much media should the carousel preload?
Prioritize the active slide, preload a small neighbor window based on direction and connection evidence, and leave distant slides as reserved placeholders. Keep dimensions stable so decoding does not shift the track.