General
Carousel
Usage#
import { WDS_CAROUSEL } from '@wds/angular/carousel';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#
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-default-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel class="w-full max-w-xs">
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselDefaultDemo {}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.
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-controls-outside-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel controls="outside" class="mx-12 w-full max-w-xs">
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselControlsOutsideDemo {}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.
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-per-view-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel class="w-full max-w-lg [--wds-carousel-gap:12px] [--wds-carousel-per-view:2] sm:[--wds-carousel-per-view:3]">
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">6</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">7</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-3xl font-semibold">8</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselPerViewDemo {}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.
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-center-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel align="center" class="w-full max-w-lg [--wds-carousel-per-view:1.5]">
<wds-carousel-item>
<wds-card>
<div class="flex aspect-video items-center justify-center text-4xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-video items-center justify-center text-4xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-video items-center justify-center text-4xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-video items-center justify-center text-4xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-video items-center justify-center text-4xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselCenterDemo {}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.
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-vertical-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel orientation="vertical" class="w-full max-w-xs my-12 [--wds-carousel-height:200px]" controls="outside">
<wds-carousel-item>
<wds-card class="h-full [&::part(content)]:my-auto">
<div class="flex justify-center text-4xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full [&::part(content)]:my-auto">
<div class="flex justify-center text-4xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full [&::part(content)]:my-auto">
<div class="flex justify-center text-4xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full [&::part(content)]:my-auto">
<div class="flex justify-center text-4xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full [&::part(content)]:my-auto">
<div class="flex justify-center text-4xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselVerticalDemo {}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.
import { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-indicators-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel indicators loop class="w-full max-w-xs">
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">1</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">2</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">3</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">4</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">5</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselIndicatorsDemo {}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 studioimport { Component } from '@angular/core';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
import { WdsCardComponent } from '@wds/angular/card';
@Component({
selector: 'app-carousel-autoplay-demo',
imports: [WdsCarouselComponent, WdsCarouselItemComponent, WdsCardComponent],
template: `
<wds-carousel autoplay="4000" indicators loop label="Customer quotes" class="w-full max-w-md">
<wds-carousel-item>
<wds-card class="h-full">
<div class="flex h-full flex-col justify-between gap-6">
<p class="text-lg font-medium">“Onboarding took one afternoon instead of a week.”</p>
<span class="text-sm text-muted-foreground">Head of Support, a logistics company</span>
</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full">
<div class="flex h-full flex-col justify-between gap-6">
<p class="text-lg font-medium">“We replaced three spreadsheets with one shared board.”</p>
<span class="text-sm text-muted-foreground">Operations lead, a regional clinic</span>
</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full">
<div class="flex h-full flex-col justify-between gap-6">
<p class="text-lg font-medium">“Planning meetings got shorter by half.”</p>
<span class="text-sm text-muted-foreground">Engineering manager, a fintech startup</span>
</div>
</wds-card>
</wds-carousel-item>
<wds-carousel-item>
<wds-card class="h-full">
<div class="flex h-full flex-col justify-between gap-6">
<p class="text-lg font-medium">“Our new hires find answers without asking anyone.”</p>
<span class="text-sm text-muted-foreground">People partner, a design studio</span>
</div>
</wds-card>
</wds-carousel-item>
</wds-carousel>
`,
})
export class CarouselAutoplayDemo {}Thumbnails and counter#
index, which scrolls the carousel; wds-change keeps them and the counter in step when the slides are swiped or moved with the arrows.
Slide 1 of 5
import { Component, signal } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsCardComponent } from '@wds/angular/card';
import { WdsCarouselComponent, WdsCarouselItemComponent } from '@wds/angular/carousel';
const SLIDES = [1, 2, 3, 4, 5];
@Component({
selector: 'app-carousel-thumbnails-demo',
host: { class: 'flex w-full max-w-xs flex-col items-center gap-3' },
imports: [WdsButtonComponent, WdsCardComponent, WdsCarouselComponent, WdsCarouselItemComponent],
template: `
<wds-carousel class="w-full" [index]="index()" (wdsChange)="index.set($event.index)">
@for (slide of slides; track slide) {
<wds-carousel-item>
<wds-card>
<div class="flex aspect-square items-center justify-center text-4xl font-semibold">{{ slide }}</div>
</wds-card>
</wds-carousel-item>
}
</wds-carousel>
<div class="flex gap-2">
@for (slide of slides; track slide; let i = $index) {
<wds-button
size="sm"
[variant]="i === index() ? 'default' : 'outline'"
[label]="'Slide ' + slide"
[attr.aria-current]="i === index() ? 'true' : null"
(click)="index.set(i)"
>{{ slide }}</wds-button
>
}
</div>
<p class="text-sm text-muted-foreground">Slide {{ index() + 1 }} of {{ slides.length }}</p>
`,
})
export class CarouselThumbnailsDemo {
protected readonly slides = SLIDES;
/** The selected slide: set by the buttons below and by the carousel itself. */
protected readonly index = signal(0);
}API References#
wds-carousel-item#
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
| Attribute | Type | Default | Description |
|---|---|---|---|
| label | string | '' |
Slots
| Slot | Description |
|---|---|
| (default) |
wds-carousel#
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
| Attribute | Type | Default | Description |
|---|---|---|---|
| orientation | WdsCarouselOrientation | 'horizontal' | horizontal) or a column (vertical, with --wds-carousel-height). |
| align | WdsCarouselAlign | 'start' | --wds-carousel-per-view). |
| controls | WdsCarouselControls | 'inside' | |
| indicators | boolean | false | |
| loop | boolean | false | |
| autoplay | number | 0 | |
| label | string | '' | |
| index | number | 0 |
Events
| Event | Description |
|---|---|
| wds-changeCustomEvent<WdsCarouselChangeDetail> |
Methods
| Method | Description |
|---|---|
| next() | loop, from the last back to the first). |
| prev() | loop, from the first to the last). |
| goTo(index: number, options: { smooth?: boolean }) | smooth: false jumps without animation. |
Slots
| Slot | Description |
|---|---|
| (default) | wds-carousel-item elements. |
CSS parts (::part)
| Part | Description |
|---|---|
| base | |
| viewport | |
| track | |
| previous | |
| next | |
| footer | |
| indicators | |
| indicator | indicator-active. |
| autoplay-toggle |
CSS custom properties
| Property | Description |
|---|---|
| --wds-carousel-gap | |
| --wds-carousel-per-view | |
| --wds-carousel-item-size | --wds-carousel-per-view (e.g. 14rem). |
| --wds-carousel-height | orientation="vertical" (default 16rem). |
Accessibility#
Screen reader#
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.
inert and aria-hidden, so Tab skips links and buttons in them.
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.
aria-current="true".
Keyboard support#
| Key | Function |
|---|---|