Example of Image Carousel with Automatically Rotating Images
++ This example section demonstrates a design pattern for a image carousel consisting of a pause button, next and previous slide buttons. + In this example, when the page is loaded the carousel images start rotating automatically. + The auto rotation can be stopped by activating the pause button, just moving keyboard focus to any control or link in the carousel or hovering the over carousel content with a mouse. There are two ways for the user to restart rotation, pressing the pause button again or moving the pointer outside the carousel image area. + For additional guidance, see Deciding When to Make Selection Automatically Follow Focus. +
+ + + +Example
+ +Accessibility Features
+-
+
- + Image rotation stops when keyboard focus enters the controls or content of the carousel. + +
- + Pause button is to provide a means of screen reader users using review mode to be aware of auto-updating content and stop the rotation. + +
- + To improve readability of the caption text and content, background contrast is improved by decreasing the transparency of the caption area. This improves the color contrast radio of the white text, especially when light colored image are used in the background. + +
Keyboard Support
+ +Pause Slide Rotation Button
+Key | +Function | +Tab | ++ The button becomes visible when it receives keyboard focus. + | + +
---|---|
Enter or Space | +
+
|
+
Next/Previous Slide Buttons
+Key | +Function | +
---|---|
Enter or Space | ++ Moves content to the next or previous slide in the image carousel. + | +
Role, Property, State, and Tabindex Attributes
+ +Region Landmark
+Role | +Attribute | +Element | +Usage | +
---|---|---|---|
+ region
+ |
+ + |
+ section
+ |
+
+
|
+
+ |
+ aria-label=
+ |
+
+ section
+ |
+ Provides a label that describes the carousel region. | +
Start/Pause Slide Rotation
+Role | +Attribute | +Element | +Usage | +
---|---|---|---|
+ button
+ |
+ + |
+ button
+ |
+
+
|
+
+ |
+ aria-pressed=
+ |
+
+ button
+ |
+
+
|
+
+ |
+ aria-pressed=
+ |
+
+ button
+ |
+ When aria-pressed= the carousel auto-rotation is disabled. |
+
Next/Previous Slide Buttons
+Role | +Attribute | +Element | +Usage | +
---|---|---|---|
+ button
+ |
+ + |
+ a
+ |
+
+
|
+
+ |
+ aria-label=
+ |
+
+ a
+ |
+ Defines the accessible name for the next and previous slide buttons. | +
+ |
+ aria-controls=
+ |
+
+ a
+ |
+
+
|
+
Javascript and CSS Source Code
+-
+
- CSS: carousel.css +
- Javascript: carousel.js +
- Javascript: carouselItem.js +
- Javascript: carouselButtons.js +
- Javascript: pauseButton.js +
HTML Source Code
+ +
+
+
+