Carousel
<wa-carousel>
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.
Examples
Pagination
Use the pagination attribute to show the total number of slides and the current slide as a set of interactive dots.
Navigation
Use the navigation attribute to show previous and next buttons.
Looping
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.
Autoplay
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.
Mouse Dragging
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.
Multiple Slides Per View
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.
Adding and Removing Slides
The content of the carousel can be changed by adding or removing carousel items. The carousel will update itself automatically.
Vertical Scrolling
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.
Aspect Ratio
Use the --aspect-ratio custom property to customize the size of the carousel's viewport from the default value of 16/9.
Scroll Hint
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.
Gallery Example
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.
Importing
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.
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
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The carousel's main content, one or more <wa-carousel-item> elements. |
next-icon
|
Optional next icon to use instead of the default. Works best with <wa-icon>. |
previous-icon
|
Optional previous icon to use instead of the default. Works best with <wa-icon>. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
autoplayautoplay |
When set, the slides will scroll automatically when the user is not interacting with them.
Type
booleanDefault
false |
|
|
autoplayIntervalautoplay-interval |
Specifies the amount of time, in milliseconds, between each automatic scroll.
Type
numberDefault
3000 |
||
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
styles |
||
looploop |
When set, allows the user to navigate the carousel in the same direction indefinitely.
Type
booleanDefault
false |
|
|
mouseDraggingmouse-dragging |
When set, it is possible to scroll through the slides by dragging them with the mouse.
Type
booleanDefault
false |
|
|
navigationnavigation |
When set, show the carousel's navigation.
Type
booleanDefault
false |
|
|
orientationorientation |
Specifies the orientation in which the carousel will lay out.
Type
'horizontal' | 'vertical'Default
'horizontal' |
||
paginationpagination |
When set, show the carousel's pagination indicators.
Type
booleanDefault
false |
|
|
slidesPerMoveslides-per-move |
Specifies the number of slides the carousel will advance when scrolling, useful when specifying a
slides-per-page
greater than one. It can't be higher than slides-per-page.Type
numberDefault
1 |
||
slidesPerPageslides-per-page |
Specifies how many slides should be shown at a given time.
Type
numberDefault
1 |
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
goToSlide() |
Scrolls the carousel to the slide specified by index. |
index: number,
behavior: ScrollBehavior
|
next() |
Move the carousel forward by slides-per-move slides. |
behavior: ScrollBehavior
|
previous() |
Move the carousel backward by slides-per-move slides. |
behavior: ScrollBehavior
|
Events
Learn more about events.
| Name | Description |
|---|---|
wa-slide-change |
Emitted when the active slide changes. |
CSS custom properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--aspect-ratio |
The aspect ratio of each slide.
Default
16/9
|
--scroll-hint |
The amount of padding to apply to the scroll area, allowing adjacent slides to become partially visible as a scroll hint.
|
--slide-gap |
The space between each slide.
Default
var(--wa-space-m)
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The carousel's internal wrapper. |
::part(base)
|
navigation |
The navigation wrapper. |
::part(navigation)
|
navigation-button |
The navigation button. |
::part(navigation-button)
|
navigation-button-next |
Applied to the next button. |
::part(navigation-button-next)
|
navigation-button-previous |
Applied to the previous button. |
::part(navigation-button-previous)
|
pagination |
The pagination indicators wrapper. |
::part(pagination)
|
pagination-item |
The pagination indicator. |
::part(pagination-item)
|
pagination-item-active |
Applied when the item is active. |
::part(pagination-item-active)
|
scroll-container |
The scroll container that wraps the slides. |
::part(scroll-container)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.