Auto-Rotating Image Carousel with Tabs for Slide Control Example
Read This First
The code in this example is not intended for production environments.
Before using it for any purpose, read this to understand why.
This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.
- There may be support gaps in some browser and assistive technology combinations, especially for mobile/touch devices. Testing code based on this example with assistive technologies is essential before considering use in production systems.
- The ARIA and Assistive Technologies Project is developing measurements of assistive technology support for APG examples.
- Robust accessibility can be further optimized by choosing implementation patterns that maximize use of semantic HTML and heeding the warning that No ARIA is better than Bad ARIA.
About This Example
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. This example also illustrates how to use the tabs pattern to provide users with a way to skip slides in the sequence by directly choosing which one to view. Navigation among slides is provided by a series of circular buttons that function as tabs and are rendered over the rotating slides. Automatic 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 aspects of the design in detail.
Similar examples include:
- Auto-Rotating Image Carousel with Buttons for Slide Control: A basic image carousel that demonstrates the accessibility features necessary for carousels that rotate automatically on page load and also enables users to choose which slide is displayed with buttons for previous and next slide.
Example Options
Example
Accessibility Features
Controlling Automatic Slide Rotation
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 that prevents rotation, such as keyboard focus, has been triggered.
-
Moving keyboard focus to any of the carousel content, including the tab elements, pauses automatic rotation.
Automatic rotation only resumes if the user explicitly activates the
Play
button. -
The carousel also contains a rotation control button that can stop and start automatic rotation.
- The rotation control button is the first element in the screen reader reading order.
- The rotation control button is always visible so it is available to all users whether they are interacting via a mouse, keyboard, assistive technology, or touch.
- If the carousel is rotating, the button's accessible name is
Stop Automatic Slide Show
, informing screen reader users that the slides are changing in addition to providing a way to stop the changes. - If the carousel is not rotating, the accessible name of the button is
Start Automatic Slide Show
. - If a user activates the rotation control button to start rotation it is assumed the user wants auto-rotation to start immediately and focus or hover states within the carousel are ignored.. The rotation will only stop if the button is activated again,
- The example includes an option to completely disable automatic slide rotation. When this option is selected the start/stop button is not rendered and slides can only be rotated through activation of the tab controls.
Color Contrast of Text and Rotation Controls
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:
- When the tabs controlling the rendering of slides are inside the image, the tabs have foreground and background colors that meet WCAG 2.1 color contrast requirements. In addition, the focus styling uses SVG images that make the focus indicator highly visible when a control receives keyboard focus.
- The transparency of the caption area is decreased so the caption text meets the WCAG 2.1 color contrast requirements.
One way to avoid the color contrast issues of controls and text inside the image is to move them to outside the image. Moving the controls and text to a solid background makes it easier for the author to control color contrast and for the user to perceive them. An example of this technique is one of the view options.
Focus Styling of the Tablist and Tabs
- When a tab receives focus, the entire tab list is also highlighted with a border as an affordance that indicates to users that arrow keys are used to navigate among controls in the group.
- The CSS border width used for focus styling is changed from 0 to 2 pixels when the control receives focus to support visibility of focus when operating system high contrast options are enabled.
Screen Reader Announcement of Slide Changes
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 a new tab, 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.
Note that making a tab panel live is not recommended for typical tabs. In the carousel use case, where the primary intent is quick, light-weight scanning of content, the live region is used to simulate the type of experience that non-screen reader users have with auto-rotation.
Keyboard Support
Rotation Control Button
Key | Function |
---|---|
Tab |
|
Enter or Space | Toggle automatic rotation of slides in the carousel. |
Tabs
Key | Function |
---|---|
Tab |
|
Right Arrow |
|
Left Arrow |
|
Home | Moves focus to the first tab and shows the first slide. |
End | Moves focus to the last tab and shows the last slide. |
Role, Property, State, and Tabindex Attributes
Rotation Control
Role | Attribute | Element | Usage |
---|---|---|---|
aria-label
|
button
|
The accessible name changes to reflect the action the button will perform:
|
Tabs
Role | Attribute | Element | Usage |
---|---|---|---|
Implied role of region |
section
|
|
|
aria-roledescription="carousel"
|
section
|
|
|
aria-label="Highlighted television shows"
|
section
|
Provides a label that describes the content in the carousel region. | |
aria-live="off"
|
div.carousel-items
|
|
|
aria-live="polite"
|
div.carousel-items
|
|
|
tablist
|
div
|
Indicates that the element serves as a container for a set of tabs. | |
aria-label="Slides"
|
div
|
Provides an accessible name for the tablist. | |
tab
|
button
|
|
|
aria-label="Slide X"
|
button
|
Provides an accessible name for the tab. | |
aria-selected="true"
|
button
|
|
|
aria-selected="false"
|
button
|
|
|
tabindex="-1"
|
button
|
|
|
aria-controls="IDREF"
|
button
|
Refers to the tabpanel element associated with the tab. |
|
tabpanel
|
div
|
|
|
aria-roledescription="slide"
|
div
|
|
|
aria-label="X of Y"
|
div
|
|
Javascript and CSS Source Code
- CSS: carousel-tablist.css
- Javascript: carousel-tablist.js
HTML Source Code