Create

General

Carousel

New
Copy page View as Markdown Open in ChatGPT Open in Claude

Slides that scroll one after another in a row or a column, with buttons, dots, swiping and the keyboard.

Usage#

app.component.ts
import { WDS_CAROUSEL } from '@wds/angular/carousel';

Put wds-carousel-item slides in wds-carousel. The carousel scrolls natively with snap points: touch, a trackpad and the scroll wheel work as usual, and with a mouse the slides can be dragged. index is the selected position and wds-change reports every change; next(), prev() and goTo() move it from code.

Examples#

Default#

One slide in view, with previous and next buttons over its edges. The buttons turn off at the first and the last slide.

1
2
3
4
5

Controls outside#

controls="outside" moves the buttons out of the slides; give the carousel a margin of about 48px on those sides (here mx-12). controls="none" hides them.

1
2
3
4
5

Several slides in view#

--wds-carousel-per-view sets how many slides fit in view (here 2, and 3 from sm), --wds-carousel-gap the space between them. A position is then the first slide in view, so there are fewer positions than slides. --wds-carousel-item-size gives the slides a fixed size instead.

1
2
3
4
5
6
7
8

Centered#

align="center" stops each slide in the middle; with a fractional --wds-carousel-per-view (here 1.5) the neighbors peek in from both sides.

1
2
3
4
5

Vertical#

orientation="vertical" scrolls a column of slides; --wds-carousel-height sets the height of the viewport and the up and down arrow keys move it.

1
2
3
4
5

Indicators and loop#

indicators adds a dot for each position under the slides. With loop Next goes from the last slide back to the first and Previous the other way, so the buttons never turn off.

1
2
3
4
5

Autoplay#

autoplay="4000" moves to the next slide every 4 seconds, then back to the first. It pauses while the pointer is over the carousel or focus is inside it and while the tab is hidden, and starts paused when the user prefers reduced motion. The button next to the dots stops and starts it.

“Onboarding took one afternoon instead of a week.”

Head of Support, a logistics company

“We replaced three spreadsheets with one shared board.”

Operations lead, a regional clinic

“Planning meetings got shorter by half.”

Engineering manager, a fintech startup

“Our new hires find answers without asking anyone.”

People partner, a design studio

Thumbnails and counter#

The buttons below set index, which scrolls the carousel; wds-change keeps them and the counter in step when the slides are swiped or moved with the arrows.

1
2
3
4
5
12345

Slide 1 of 5

API References#

One slide of a wds-carousel. Its size along the scroll axis comes from the carousel (--wds-carousel-per-view or --wds-carousel-item-size); the content fills it. The carousel names it „Slide 2 of 5” for screen readers and takes slides that are mostly out of view out of the tab order.

Attributes

AttributeTypeDefaultDescription
labelstring''Accessible name of the slide, instead of „Slide 2 of 5”.

Slots

SlotDescription
(default)Content of the slide.

Slides that scroll one after another in a row or a column. Each slide is a wds-carousel-item; the carousel adds previous and next buttons, and with indicators a dot for each position. It scrolls natively with snap points, so touch, a trackpad and the scroll wheel work as usual; with a mouse the slides can also be dragged. Several slides fit in view with --wds-carousel-per-view (e.g. md:[--wds-carousel-per-view:3]); a position is then the first slide in view, and the last position is the one that shows the last slide. autoplay moves to the next slide every given number of milliseconds and pauses on hover, on focus and while the tab is hidden; it starts paused when the user prefers reduced motion. A button in the footer stops and starts it.

Attributes

AttributeTypeDefaultDescription
orientationWdsCarouselOrientation'horizontal'Lays the slides out in a row (horizontal) or a column (vertical, with --wds-carousel-height).
alignWdsCarouselAlign'start'Where a slide stops: at the start of the viewport or in its center (e.g. with a fractional --wds-carousel-per-view).
controlsWdsCarouselControls'inside'Previous and next buttons: over the edges of the slides, outside them (give the carousel a margin of about 48px on those sides), or none.
indicatorsbooleanfalseShows a dot for each position under the slides.
loopbooleanfalseAfter the last position, Next goes back to the first one (and Previous from the first to the last).
autoplaynumber0Moves to the next position every given number of milliseconds, then back to the first. 0 turns it off.
labelstring''Accessible name of the carousel (defaults to „Carousel”).
indexnumber0The selected position, counted from 0. Setting it scrolls there; it follows scrolling, the buttons and the dots.

Events

EventDescription
wds-changeCustomEvent<WdsCarouselChangeDetail>The selected position changed (buttons, dots, keys, scrolling or autoplay).

Methods

MethodDescription
next()Scrolls to the next position (with loop, from the last back to the first).
prev()Scrolls to the previous position (with loop, from the first to the last).
goTo(index: number, options: { smooth?: boolean })Scrolls to a position, counted from 0 (clamped to the existing ones). smooth: false jumps without animation.

Slots

SlotDescription
(default)wds-carousel-item elements.

CSS parts (::part)

PartDescription
baseThe region around the viewport, the buttons and the footer.
viewportThe scrolling area.
trackThe row (or column) of slides.
previousThe previous button.
nextThe next button.
footerThe row under the slides with the autoplay button and the dots.
indicatorsThe group of dots.
indicatorOne dot; the selected one also has indicator-active.
autoplay-toggleThe button that stops and starts autoplay.

CSS custom properties

PropertyDescription
--wds-carousel-gapSpace between slides (default 16px).
--wds-carousel-per-viewNumber of slides in view, may be fractional (default 1).
--wds-carousel-item-sizeSize of a slide along the scroll axis, instead of --wds-carousel-per-view (e.g. 14rem).
--wds-carousel-heightHeight of the viewport with orientation="vertical" (default 16rem).

Accessibility#

Screen reader#

The carousel is a region with aria-roledescription="carousel" and the name from label (by default „Carousel”). Each slide is a group with aria-roledescription="slide" named „2 of 5”; label on a slide overrides it.

Slides less than half in view are inert and aria-hidden, so Tab skips links and buttons in them.

The viewport is a live region (aria-live="polite"), so the new slide is read after a button press. While autoplay runs it is off, so a rotating slide does not interrupt; the autoplay button („Stop the slide show” and „Start the slide show”) gives control back.

The dots are buttons named „Go to slide 3”; the selected one has aria-current="true".

Keyboard support#

KeyFunction
TabMoves focus to the slides (the viewport), the previous and next buttons, the autoplay button and the dots. Focus inside pauses autoplay.
ArrowLeftWith focus on the slides, scrolls to the previous position (the next one in right-to-left layouts).
ArrowRightWith focus on the slides, scrolls to the next position (the previous one in right-to-left layouts).
ArrowUpIn a vertical carousel, scrolls to the previous position.
ArrowDownIn a vertical carousel, scrolls to the next position.
HomeWith focus on the slides, scrolls to the first position.
EndWith focus on the slides, scrolls to the last position.
Footer