third_party/aria-practices/src/content/patterns/carousel/examples/carousel-1-prev-next.html
The following example implementation of the Carousel 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 either move focus into the carousel or hover the mouse over carousel content, and users can manually control which slide is displayed with previous and next slide buttons. The accessibility features section that follows the example describes these features in detail.
Similar examples include:
Carousel View and Behavior Options Display controls and captions outside of image
This option is more accessible than rendering controls and captions within the image, because controls are easier to perceive and captions are easier to read without rotating images behind them.
Pause auto-rotation on load (reload needed)
This option controls whether the carousel is paused or playing on page load. The paused option improves accessibility for users with visual impairments and people who are distracted or confused by auto-rotation, but allows users to start auto-rotation using the start/stop button.
Note: If the user has chosen reduced motion in system settings, auto-rotation will always be paused on load.
Disable auto-rotation
This option improves accessibility for users with visual impairments and people who are distracted or confused by auto-rotation by disabling the auto-rotation feature and removing the start/stop button from the user interface. Users can use the previous and next buttons to manually navigate through the slides.
7 pm Tuesday, March 3, on TV
Sept. 14 to Sept. 24 or 27
8 pm Sunday, March 8, on TV: Sneak peek at the final season.
Watch the latest episodes.
Users can stop and start slide rotation, which is an essential aspect of accessibility of the carousel for a variety of people with disabilities. People with low vision or a cognitive disability that affects visual processing or reading benefit from being able to control slide rotation so they have sufficient time to explore slide content. Similarly, since screen reader users cannot perceive automatic rotation, it can make reading the page confusing and disorienting. For example, when slides are automatically rotating, a screen reader user may read an element on slide one, execute a screen reader command to read the next element, and, instead of hearing the next element on slide one, hear an element from slide 2 without any knowledge that the element just announced is from an entirely new context.
This example includes the following features for giving users control over slide rotation:
If operating system preferences have been set for reduced motion or disabling animations, the auto-rotation is initially paused.
Hovering the mouse over any carousel content pauses automatic rotation. Automatic rotation resumes when the mouse moves away from the carousel unless another condition, such as keyboard focus, that prevents rotation has been triggered.
Moving keyboard focus to any of the carousel content, including the next and previous slide elements, pauses automatic rotation. Automatic rotation resumes when keyboard focus moves out of the carousel content unless another condition, such as mouse hover, that prevents rotation has been triggered.
The carousel also contains a rotation control button that can stop and start automatic rotation.
The example includes an option to completely disable automatic slide rotation. When this option is selected the start/stop button is not rendered and the slides can only be rotated through activation of the next and previous buttons.
In the view of this carousel where the controls and captions are displayed inside the image, background images could cause color contrast for the controls and text to become insufficient. However, this view includes the following features to prevent this potential problem and ensure it meets WCAG 2.1 color contrast requirements:
One way to avoid the color contrast issues caused by displaying controls and text within the images is to position the controls outside the image. Displaying the controls and text on a solid background makes it easier to control color contrast. One of the view options provides an example of this technique.
When automatic rotation is turned off, the carousel slide content is included in a live region. This makes it easier for screen reader users to scan through the carousel slides. When screen reader users activate the next or previous slide button, the new slide content is announced, giving users immediate feedback that helps them determine whether or not to interact with the content. Very importantly, if automatic rotation is turned on, the live region is disabled. If it were not, the page would become unusable as announcements of the continuously changing content constantly interrupt anything else the user is reading.
| Key | Function |
|---|---|
| Tab |
| | Enter or Space | Toggle the auto rotation of slides in the carousel. |
| Key | Function |
|---|---|
| Enter | |
| Space | Display next or previous slide in the carousel. |
| Role | Attribute | Element | Usage |
|---|---|---|---|
region | section |
region is implied for any section element that has an accessible name.|
| | aria-roledescription="carousel" | section |
aria-roledescription value is defined using the language of the page and should be localized by the author.|
| | aria-label="Highlighted television shows" | section | Provides a label that describes the content in the carousel region. |
| | aria-live="off" | div.carousel-items |
div element that contains all the slides.|
| | aria-live="polite" | div.carousel-items |
div element that contains all the slides.|
| group | | div.carousel-item |
|
| | aria-roledescription="slide" | div.carousel-item |
group elements.aria-roledescription value is defined using the language of the page and should be localized by the author.|
| | aria-label="N of 6" | div.carousel-item |
aria-setsize or aria-posinset.|
| | aria-label="LABEL_STRING" | button | Defines the accessible name for the pause auto-rotation button and the next and previous slide buttons. |
| | aria-controls="IDREF" | button |
div that contains all the slides.|
To copy the following HTML code, please open it in CodePen.