# Carousel

The **carousel** displays a set of related content in a horizontal row, supporting to cycle through them automatically or manually by the user with navigation controls.

## Usage

Use a carousel when users need to browse a small set of related items within limited space, and each item follows a consistent structure (e.g., same card layout, similar content density).

![Carousel](<../images/carousel.png>)

### When to use

- To surface multiple related items.
- When content can be browsed one page at a time without losing context.
- When space is limited and showing all items at once would overwhelm the layout.
- In unattended display contexts (e.g., monitors, presentation screens) using slideshow mode with auto-play.

### Best practices

- Keep slides consistent in height and content structure across pages.
- Always show the auto-play control so users can pause the carousel at any time.
- Avoid mixing slides with very different content types in the same carousel.
- Use the carousel for content that is genuinely browsable, where users benefit from seeing one page at a time.
- The pagination displays a minimum of 2 and a maximum of 7 dots at a time, regardless of the total number of slides.

## Design

### Anatomy

![Carousel elements](<../images/carousel-elements.png>)

> 1. Slides, 2. Navigation controls, 3, Pagination, 4. Pause/play

Except for the slides, **all items are optional**.

### Slide layout

All slides within a carousel share the same width and height,

The carousel always shows one full-width slide. What goes inside that slot (one card, three cards, a grid, images) can be defined according to the use case.

![Carousel slide layouts](<../images/carousel-slide-layouts.png>)

### Auto-play

When auto-play is enabled, the carousel advances to the next slide after a configurable interval. A play/pause button is shown alongside the navigation controls so users can pause or resume at any time.

Auto-play works in both carousel and slideshow modes.

![Carousel auto-play](<../images/carousel-auto-play.png>)

### Slideshow mode

**Slideshow mode** expands the carousel to cover the entire viewport, hiding all application content including the app header. It is typically used for unattended display (monitors, presentation screens) and is commonly paired with auto-play.

## Code

The `si-carousel` component uses the `siCarouselItem` directive to mark each slide. Slides are displayed horizontally with snap-scroll behavior.

### Usage

```
import { SiCarouselComponent, SiCarouselItemDirective } from '@siemens/element-ng/carousel';

@Component({
  imports: [SiCarouselComponent, SiCarouselItemDirective, ...]
})
```

```
<si-carousel>
  <div siCarouselItem><h2>Slide 1</h2></div>
  <div siCarouselItem><h2>Slide 2</h2></div>
  <div siCarouselItem><h2>Slide 3</h2></div>
</si-carousel>
```

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { NgTemplateOutlet } from '@angular/common';
import { Component, computed, inject, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SiCardComponent } from '@siemens/element-ng/card';
import { SiCarouselComponent, SiCarouselItemDirective } from '@siemens/element-ng/carousel';
import { ContentActionBarMainItem } from '@siemens/element-ng/content-action-bar';
import { SiFormItemComponent } from '@siemens/element-ng/form';
import { MenuItem } from '@siemens/element-ng/menu';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [
    SiCarouselComponent,
    SiCarouselItemDirective,
    SiCardComponent,
    SiFormItemComponent,
    FormsModule,
    NgTemplateOutlet
  ],
  templateUrl: './si-carousel.html',
  styles: `
    si-carousel si-card {
      block-size: 100%;
      min-block-size: 175px;
    }
  `
})
export class SampleComponent {
  private readonly logEvent = inject(LOG_EVENT);
  readonly autoPlay = signal(false);
  readonly autoPlayDuration = signal(6000);
  readonly slideShowMode = signal(false);
  readonly additionalItemsCount = signal(0);
  readonly withoutPageControls = signal(false);
  readonly additionalItems = computed(() => Array.from({ length: this.additionalItemsCount() }));

  readonly primaryActions: ContentActionBarMainItem[] = [
    { type: 'action', label: 'Settings', action: () => this.logEvent('Settings clicked') },
    { type: 'action', label: 'Copy', action: () => this.logEvent('Copy clicked') },
    { type: 'action', label: 'Delete', action: () => this.logEvent('Delete clicked') }
  ];

  readonly secondaryActions: MenuItem[] = [
    { type: 'action', label: 'Settings', action: () => this.logEvent('Settings clicked') },
    { type: 'action', label: 'Copy', action: () => this.logEvent('Copy clicked') }
  ];
}
```

Template:

```html
<div class="d-flex flex-column p-5" [class.h-100]="slideShowMode()">
  <si-carousel
    [autoPlay]="autoPlay() ? autoPlayDuration() : false"
    [hidePageControls]="withoutPageControls()"
  >
    @if (slideShowMode()) {
      @for (item of [totalUsers, revenue, conversion]; track $index) {
        <!-- In slide show mode each card is displayed individually as a carousel item -->
        <div siCarouselItem>
          <ng-container *ngTemplateOutlet="item" />
        </div>
      }
    } @else {
      <div siCarouselItem>
        <div class="d-flex flex-column flex-sm-row gap-5 h-100">
          @for (item of [totalUsers, revenue, conversion]; track $index) {
            <div class="flex-fill">
              <ng-container *ngTemplateOutlet="item" />
            </div>
          }
        </div>
      </div>
    }

    @for (item of [1, 2, 3]; track $index) {
      <div siCarouselItem>
        <si-card [heading]="'Placeholder slide ' + ($index + 1)">
          <p body class="card-body card-text">Placeholder carousel slide {{ $index + 1 }}</p>
        </si-card>
      </div>
    }

    @for (item of additionalItems(); track $index) {
      <div siCarouselItem>
        <si-card [heading]="'Additional Item ' + ($index + 1)">
          <p body class="card-body card-text">Placeholder carousel item {{ $index + 1 }}</p>
        </si-card>
      </div>
    }
  </si-carousel>

  @if (!slideShowMode()) {
    <si-card heading="Settings" class="e2e-ignore mt-4" style="height: 150px">
      <div class="card-body pt-1" body>
        <div class="row">
          <div class="col-sm-4">
            <si-form-item label="Auto play">
              <input
                class="form-check-input"
                type="checkbox"
                id="auto-play"
                [(ngModel)]="autoPlay"
              />
            </si-form-item>
          </div>
          <div class="col-sm-4">
            <si-form-item label="Slide show mode">
              <input
                class="form-check-input"
                type="checkbox"
                id="slide-show-mode"
                [(ngModel)]="slideShowMode"
              />
            </si-form-item>
          </div>
          <div class="col-sm-4">
            <si-form-item label="Without page controls">
              <input
                class="form-check-input"
                type="checkbox"
                id="without-page-controls"
                [(ngModel)]="withoutPageControls"
              />
            </si-form-item>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4">
            <si-form-item label="Auto play duration (ms)">
              <input
                type="number"
                min="500"
                step="500"
                class="form-control"
                id="auto-play-duration"
                [(ngModel)]="autoPlayDuration"
              />
            </si-form-item>
          </div>
          <div class="col-sm-3">
            <si-form-item label="Extra slides">
              <input
                type="number"
                min="0"
                max="10"
                class="form-control"
                id="additional-items"
                [(ngModel)]="additionalItemsCount"
              />
            </si-form-item>
          </div>
        </div>
      </div>
    </si-card>
  }
</div>

<!-- KPI cards-->
<ng-template #totalUsers>
  <si-card heading="Total users" subHeading="Latest 30 days">
    <div body class="card-body card-text">
      <div class="display-6 fw-bold">12,450</div>
      <div class="text-secondary">&uarr; 15% from last month</div>
    </div>
  </si-card>
</ng-template>
<ng-template #revenue>
  <si-card heading="Revenue" subHeading="Monthly">
    <div body class="card-body card-text">
      <div class="display-6 fw-bold">$24,580</div>
      <div class="text-secondary">&uarr; 8% from last month</div>
    </div>
  </si-card>
</ng-template>
<ng-template #conversion>
  <si-card heading="Conversion" subHeading="This quarter">
    <div body class="card-body card-text">
      <div class="display-6 fw-bold">3.24%</div>
      <div class="text-secondary">&darr; 0.5% from last month</div>
    </div>
  </si-card>
</ng-template>
```

### [SiCarouselComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L103-L587>)

**Kind:** component

**Selector:** `si-carousel`

```
import { SiCarouselComponent } from '@siemens/element-ng/carousel';
```

A carousel component for displaying slides with navigation controls and auto-play.

Features horizontal scrolling with snap behavior, pagination dots, and ARIA accessibility. Suitable for dashboards, image galleries, and content showcases.

Example:

```typescript
import { SiCarouselComponent, SiCarouselItemDirective } from '@siemens/element-ng/carousel';

@Component({
  imports: [SiCarouselComponent, SiCarouselItemDirective],
  template: `
    <si-carousel>
      <div siCarouselItem><h2>Slide 1</h2></div>
      <div siCarouselItem><h2>Slide 2</h2></div>
      <div siCarouselItem><h2>Slide 3</h2></div>
    </si-carousel>
  `
})
export class MyComponent {}
```

```
component SiCarouselComponent
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [ariaRole](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L121-L121>) | `"region" \| "group"` | `'region'` | Aria role of the carousel element. Can be set to 'region' or 'group' depending on the desired accessibility semantics. |
| [autoPlay](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L116-L116>) | `number \| boolean` | `false` | Enables or configures auto-play for the carousel. When set to `true`, the carousel automatically navigates to the next slide every 5000 milliseconds (5 seconds). Pass a positive number to set a custom interval in milliseconds. Pass `false` to disable auto-play. |
| [carouselRoleDescription](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L177-L179>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.ROLE_DESCRIPTION:carousel` `` | Role description for the carousel container, used for accessibility purposes. |
| [hidePageControls](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L109-L109>) | `boolean` | `false` | Controls whether pagination controls are shown. When `true`, the carousel shows one slide per page and hides pagination controls. |
| [nextButtonAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L140-L140>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.NEXT:Next slide` `` | Aria label for the next button, used for accessibility purposes. |
| [pauseButtonLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L168-L168>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.PAUSE:Pause` `` | Label for the pause button when autoplay is active. |
| [playButtonLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L159-L159>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.PLAY:Play` `` | Label for the play button when autoplay is paused. |
| [previousButtonAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L130-L132>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.PREVIOUS:Previous slide` `` | Aria label for the previous button, used for accessibility purposes. |
| [slidePageAriaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L148-L150>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.SLIDE_PAGE:Slide {{page}} of {{total}}` `` |  |
| [slideRoleDescription](<https://github.com/siemens/element/blob/main/projects/element-ng/carousel/si-carousel.component.ts#L187-L189>) | `TranslatableString` | `` $localize`:@@SI_CAROUSEL.SLIDE_ROLE_DESCRIPTION:Slide` `` | Role description for each slide, used for accessibility purposes. |

### Types Documentation

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
