Image Carousel
UI Coding
Medium
30 min
accessibility
state
keyboard
Build an ImageCarousel component that shows one image at a time from a list of images.
The starter file has the image data and a static layout that always shows the first image. Make it work.
Requirements
- The first image is shown initially. Only the current image is rendered as an
<img>, with itsalttext. - A Previous and a Next button move between images. Navigation wraps around: Next on the last image shows the first, Previous on the first shows the last.
- A row of dot buttons, one per image, jumps straight to that image. The dot for the current image is marked with
aria-current="true". - Accessibility, following the WAI-ARIA Carousel pattern:
- The carousel is a
<section>witharia-roledescription="carousel"and anaria-label. - The slide is a
role="group"witharia-roledescription="slide"and a label like"2 of 5". - Icon-only buttons have accessible names:
"Previous image","Next image"and"Show image N"for the dots. - Screen-reader users hear the new slide when they navigate (
aria-live="polite"on the slide container).
- The carousel is a
- Keyboard: when focus is inside the carousel, <kbd>←</kbd> / <kbd>→</kbd> go to the previous / next image.
- The image area keeps a fixed aspect ratio so the controls don't jump while images load.
Follow-up
- Add autoplay. What does the APG say about pausing it (hover, focus, an explicit pause button)?
- Animate the transition between slides (see Image Carousel II).
- How would you avoid a blank flash when moving to an image that hasn't loaded yet?
Spotted a mistake or a rights concern? Report an issue