Skip to content

Carousel

The carousel is used to display a set of images or content in a neat way.

These carousels have can be scrolled by holding SHIFT and scrolling the mouse wheel, vertically scrolling with a track pad, setting the focus on the carousel by clicking it or navigating to it using keyboard navigation and using the arrow keys to navigate through the carousel.

The basic html structure of the carousel is seen below, applying the base styles without providing any more complex behaviour such as scroll snapping.

Alternate Layout : Tight

Applying the carousel-tight class will remove the gap between the items.

Snapping Styles

A number of snapping styles have been provided, giving you the option for how you would like the carousel to behave. It is recommended to choose one of these, as it will improve the keyboard navigation within your carousel as users can quickly navigate through the items.

Start Snap

The carousel-snap-start class will snap the items to the left edge of the carousel.

End Snap

The carousel-snap-end class will snap the items to the right edge of the carousel.

Center Snap

The carousel-snap-center class will snap the items to the middle of the carousel.

Snap Alignment

By adding the carousel-align class, additional padding is added to the carousel such that all items will follow the snapping style.

Content can be added as well as images, and should be placed within a div with the class carousel-content applied.

By adding the carousel-banner class, the items will become full width, with the content and image placed next to each other.

If a carousel item contains only one child, it will be full width regardless of the banner image width variable.

Variables

The carousel can be customized with the following variables:

Layout Variables

VariableDefault ValueDescription
--carousel-item-gap1remGap between carousel items
--carousel-content-padding0remPadding around content
--carousel-image-height300pxHeight of carousel images
--carousel-item-width300pxWidth of carousel items
--carousel-banner-image-width50%Width of banner images
--carousel-banner-image-height400pxHeight of banner images
--carousel-banner-image-height-mobile300pxHeight of banner images on mobile

Visual Effects Variables

VariableDefault ValueDescription
--carousel-radiusvar(--radius-site)Border radius for carousel items
--carousel-animation-speedvar(--duration-speed-default)Speed of animations

Focus Variables

VariableDefault ValueDescription
--carousel-focus-width2pxWidth of the focus outline
--carousel-focus-offset2pxOffset distance of the focus outline

Accessibility

  • Include control buttons for all carousels
  • Keep screen aria labels updated to match current content.
  • Trap focus when interactive elements are used within the carousel items.

See the W3 ARIA carousel documentation for more information

Further reading

Carousel Pattern on W3C Web Accessibility Initiative https://www.w3.org/WAI/ARIA/apg/patterns/carousel/

W3.org carousel tutorial https://www.w3.org/WAI/tutorials/carousels/

CSS Only Carousel CSS-Tricks https://css-tricks.com/css-only-carousel/