Carousel

<wa-carousel> Experimental Since 2.2

Carousels display a series of content slides along a horizontal or vertical axis, one or more at a time. Users can navigate between slides with controls, pagination, or autoplay.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Examples

Link to This Section

Pagination

Link to This Section

Use the pagination attribute to show the total number of slides and the current slide as a set of interactive dots.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)
Link to This Section

Use the navigation attribute to show previous and next buttons.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Looping

Link to This Section

By default, the carousel will not advanced beyond the first and last slides. You can change this behavior and force the carousel to "wrap" with the loop attribute.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Autoplay

Link to This Section

The carousel will automatically advance when the autoplay attribute is used. To change how long a slide is shown before advancing, set autoplay-interval to the desired number of milliseconds. For best results, use the loop attribute when autoplay is enabled. Note that autoplay will pause while the user interacts with the carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Mouse Dragging

Link to This Section

The carousel uses scroll snap to position slides at various snap positions. This allows users to scroll through the slides very naturally, especially on touch devices. Unfortunately, desktop users won't be able to click and drag with a mouse, which can feel unnatural. Adding the mouse-dragging attribute can help with this.

This example is best demonstrated using a mouse. Try clicking and dragging the slide to move it. Then toggle the switch and try again.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash) Enable mouse dragging

Multiple Slides Per View

Link to This Section

The slides-per-page attribute makes it possible to display multiple slides at a time. You can also use the slides-per-move attribute to advance more than once slide at a time, if desired.

Slide 1 Slide 2 Slide 3 Slide 4 Slide 5 Slide 6

Adding and Removing Slides

Link to This Section

The content of the carousel can be changed by adding or removing carousel items. The carousel will update itself automatically.

Slide 1 Slide 2 Slide 3

Vertical Scrolling

Link to This Section

Setting the orientation attribute to vertical will render the carousel in a vertical layout. If the content of your slides vary in height, you will need to set an explicit height or max-height on the carousel using CSS.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)

Aspect Ratio

Link to This Section

Use the --aspect-ratio custom property to customize the size of the carousel's viewport from the default value of 16/9.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash) 1/1 3/2 16/9

Scroll Hint

Link to This Section

Use the --scroll-hint custom property to add inline padding in horizontal carousels and block padding in vertical carousels. This will make the closest slides slightly visible, hinting that there are more items in the carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)
Link to This Section

The carousel has a robust API that makes it possible to extend and customize. This example syncs the active slide with a set of thumbnails, effectively creating a gallery-style carousel.

The sun shines on the mountains and trees (by Adam Kool on Unsplash) A river winding through an evergreen forest (by Luca Bravo on Unsplash) The sun is setting over a lavender field (by Leonard Cotte on Unsplash) A field of grass with the sun setting in the background (by Sapan Patel on Unsplash) A scenic view of a mountain with clouds rolling in (by V2osk on Unsplash)
Thumbnail by 1 Thumbnail by 2 Thumbnail by 3 Thumbnail by 4 Thumbnail by 5

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/carousel/carousel.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/carousel/carousel.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/carousel/carousel.js';

To import this component for React 18 or below, use the following code:

import WaCarousel from '@awesome.me/webawesome/dist/react/carousel/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Methods

Link to This Section

Learn more about methods.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

CSS parts

Link to This Section

Learn more about CSS parts.

Dependencies

Link to This Section

This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.

Need a hand? Report a bug Ask for help
    No results