Auto-Rotating Image Carousel Example

NOTE: This is a new example as of the January 2019 release of WAI-ARIA Authoring Practices 1.1. Please provide feedback in issue 971.

The following example implementation of the carousel design pattern demonstrates features of the pattern that are essential to accessibility for carousels that automatically start rotating when the page loads. For instance, rotation stops when users move focus to any control or link in the carousel or hover the mouse over carousel content. The accessibility features section that follows the example describes these features in detail.

Example

Accessibility Features

Keyboard Support

Rotation Control Button

Key Function
Tab
  • Moves focus through interactive elements in the carousel.
  • Rotation control, previous slide, and next slide buttons precede the slide content in the Tab sequence.
  • The rotation control button moves on screen when it receives keyboard focus and off screen when it is not focused.
  • Off-screen positioning allows it to be available to screen reader users when not focused.
Enter or Space Toggle the auto rotation of slides in the carousel.

Next and Previous Slide Buttons

Key Function
Enter
Space
Display next or previous slide in the carousel.

Role, Property, State, and Tabindex Attributes

Role Attribute Element Usage
region section
  • Role region is implied for any section element that has an accessible name.
  • Defines the carousel and its controls as a land mark region.
aria-roledescription="carousel" section
  • Informs assistive technologies to identify the element as a "carousel" rather than a "region."
  • Effects how the assistive technology renders the role but does not effect functionality, such as commands for navigating to landmark regions.
aria-label="Highlighted television shows" section Provides a label that describes the content in the carousel region.
aria-live=off div.carousel-items
  • Applied to a div element that contains all the slides.
  • Identifies the container element as a live region that is in the "off" state, meaning assistive technology users are not informed about changes to the region.
  • The live region is off when the carousel is automatically rotating.
aria-live=polite div.carousel-items
  • Applied to a div element that contains all the slides.
  • Identifies the container element as a live region in the "polite" state, meaning assistive technology users are informed about changes to the region at the next available opportunity.
  • This causes screen readers to automatically announce the content of slides when the next and previous slide buttons are activated.
group div.carousel-item
  • Applied to each of the elements that contains the content of a single slide.
  • Enables assistive technology users to perceive the boundaries of a slide.
aria-roledescription="slide" div.carousel-item
  • Informs assistive technologies to identify the element as a "slide" rather than a "group."
  • Effects how the assistive technology renders the role but does not remove any assistive technology functions related to group elements.
aria-label="N of 6" div.carousel-item
  • Provides each slide with a distinct label that helps the user understand which of the 6 slides is displayed.
  • Note: Normally, including set position and size information in an accessible name is not appropriate. An exception is helpful in this implementation because group elements do not support aria-setsize or aria-posinset.
aria-disabled="true" button
  • Applied to the automatic rotation control button when rotation is stopped and conditions that prevent automatic rotation are present.
  • The button is disabled when a pointer is hovering over the carousel or any element in the carousel has keyboard focus.
  • The aria-disabled state is used instead of the HTML disabled attribute to keep the button in the Tab sequence.
  • If hover or focus is removed from the carousel, the aria-disabled attribute is removed from the button.
button a Identifies the element as a button.
aria-label="LABEL_STRING" a Defines the accessible name for the next and previous slide buttons.
aria-controls="IDREF" a
  • Identifies the content on the page that the button controls.
  • Refers to the div that contains all the slides.

Javascript and CSS Source Code

HTML Source Code