Carousel
Carousels allow users to cycle through a series of related content within a single row of space.
- Multiple Panel Carousel
- Examples
- Usage
- Examples
- Filmstrip Carousel
- Hero Banner Carousel
- Developer Notes
- Accessibility Notes
Multiple Panel Carousel
When to Use
- Use to display a sequence of related panels
- Use when you have limited space
- Use for smaller sets of content. Larger sets may benefit from the Filmstrip Carousel
When Not to Use
- When users are likely to want to see and/or compare all content in a single view.
Examples
- Multiple Panel (shown above)
- Filmstrip Carousel
- Hero Banner
Usage
Placement
- Multiple Panels and Filmstrip Carousels may appear anywhere on the page, but are most likely to appear at the top of the screen.
- Hero Banner carousels may only appear at the top of the screen.
Interactions
Carousels may use the following scrolling methods:
- Incremental: this user-controlled method is best for smaller content sets and/or when users are likely to want to focus on each panel independently.
- Smooth: this user-controlled method is best for larger and/or infinite data sets and when users are in a more exploratory model and likely to prefer quickly advancing through the content.
- Automatic: this method is an optional feature that can be applied only to the hero image carousel.
Content inside of carousels can be continuous, allowing it to repeat at the end of the sequence, or it can stop at the end of the sequence.
Examples
View all Examples on a demo page
Filmstrip Carousel
Carousel Panel Title
When to Use
- Use for large and/or infinite content sets, such as image results
When Not to Use
- When content would benefit from being displayed in individual panels
Additional Guidelines
- This example uses a smooth scrolling method, which allows users to scan quickly through content sets.
- There should be partial image showing as often as possible to indicate additional content.
- The height of the outer panel is variable, but the height and width of the content it contains should be consistent throughout the content set.
- On small through XL screen sizes, the arrows will display for advancing forward and back. For XS screen sizes, the arrows do not appear. In this context, partial images should appear on the left and right to provide a visual affordance of the scrolling behavior.
Hero Banner Carousel
When to Use
- Use to display a single large image on a landing or marketing-type page
When Not to Use
- Not recommended for more than 5 images within the set.
Developer Notes
- Instantiate the component by calling
new Spark.Carousel(el)
- Any modifications, additions, or removal of items, or configuration option changes requires you to call the
change()
function on the Carousel instance, this will cause the carousel to reevaluate any sizing and interaction settings - The carousel will respond to focus events by scrolling to the
.spark-carousel__item
that either is focused or contains the focused element. You can specify which.spark-carousel__item
s can be focused by giving them a[tabindex]
attribute with a non-negative integer value.
For all available methods and full API, refer to the component code on Bitbucket.
Item sizing/responsive
You can easily add responsive behaviors to items using media queries, as shown in some of the examples. In cases where you have static resources, like images, it would be best to use some methodology to load in appropriately-sized images, rather than resizing the images using css (as shown here).
Hero with Auto-Advance Example
- Add the
[data-spark-carousel-auto-advance]
attribute to the.spark-carousel
element with a numeric value to use auto-advance with specified value, in seconds, as the time between transitions. This option is only supported when using the hero treatment.
Item Panels with Item Wrapping Example
- Add the
[data-spark-carousel-wrap-items]
attribute to the.spark-carousel
element to enable item wrapping
Filmstrip with Smooth Scrolling Example
Carousel Panel Title
- Add the
[data-spark-carousel-panel]
attribute to the.spark-carousel
element to use the Filmstrip treatment - Add the
[data-spark-carousel-smooth-scroll]
attribute to the.spark-carousel
element to enable smooth scrolling. - Add the
[data-spark-carousel-smooth-scroll-center]
attribute to the.spark-carousel
element to enable after-scroll item centering when using the smooth-scroll option.
Edge Scrolling with Custom Velocity Example
- Add the
[data-spark-carousel-edge]
attribute to the.spark-carousel
element to enable edge-limited scrolling (navigation dots are not available with this option) - Add the
[data-spark-carousel-scroll-velocity]
attribute to the.spark-carousel
element with a numeric value to set the default starting scroll velocity for the carousel for forward, back, and focus events. The default velocity is 5 (measured in pixels per 1/60 second).
Accessibility Notes
Hero Carousel
Usage of the Hero Carousel requires additional attributes to make the Carousel fully accessible to assistive technologies. Because the Carousel contains image and potentially text content but is housed within a generic <div>
, the region="role"
and aria-labelled-by
attributes should be added to the .spark-carousel
element. The region
attribute ensures that the aria-label
is supported correctly, while the aria-labelled-by
attribute indicates the element that contains a label for the carousel as a whole. The value of the aria-labelled-by
attribute should be the same as the id
of the spark-assistive-text
element that lives inside the carousel.
Hero Carousel Navigation
The primary way of navigating the Hero Carousel is through interaction with the carousel controls such as the Play/Pause and arrow buttons. These controls are keyboard accessible and can be reached by the Tab key as they each have the tabindex
attribute set. This approach is to allow users to pause/play the carousel when the autoplay/auto-advance feature is enabled on the carousel.
If the autoplay/auto-advance feature is not enabled, the .spark-carousel__pause
control’s markup should be removed or hidden via CSS as it does not serve any purpose in this scenario.
Carousel Headings
It is important to provide headings or titles for Carousels to tell users what the carousels contain or reference. These can be provided through the use of headings such as <h1>-<h6>
, depending on the hierarchy of your content. In the case of the Hero Carousel, ARIA attributes are used to provide a title to assistive technologies via the aria-labelled-by
attribute for situations where a heading is not provided.
If using ARIA attributes to provide a label, the HTML element used to provide the label can be used for a heading such as <h1>-<h6>
depending on the hierarchy of your content. It is not required to use a <span>
tag.
Carousel controls
Carousels that display navigational controls with icons require aria-label
attributes to ensure assistive technologies correctly identify the purpose of the controls to users.
Skip Carousel
For Carousels other than the Hero, we have introduced a Skip Carousel link that is intended to allow keyboard users to bypass the Carousel and shift focus to the next element that is focusable. This is because the other Carousel examples are navigated by tabbing through individual “slides” or images, and as such a user has to navigate through the entire Carousel before they can shift focus to elements that appear after the Carousel. Use of this feature is recommended when there are more than 8 items within the Carousel.
Usage
We recommend adding the Skip Carousel link when there are more than 8 items in a Carousel. If fewer items are present then the .spark-carousel__skip
element can be removed from the markup. If there is a possibility that a Carousel could have a dynamic number of items, we recommend using Javascript to query the number of items in the Carousel and managing the visibility of the .spark-carousel__skip
element using available display
helper classes.
For this feature to work as intended, the href
attribute needs to be set to the first focusable element after the Carousel. This requires that said element has an id
attribute whose value matches the href
value.
When a Skip Carousel link is available, the ESC key can also be used to quickly shift focus to the link if a user has been navigating via keyboard and is partly through the Carousel.