Carousel

Free

Image carousel with optional autoplay — slide, fade, card or coverflow, horizontal or vertical, one slide or a row of cards — with dots, lines, numbers or thumbnails, prev/next arrows and a slide counter.

</>sv-carousel carouselslidermedia

Complexity tier: Interactive The primitive bar, plus: its async states are declared — none is an answer — it has a keyboard model and restores focus, and any destructive action it offers can be undone.

import { SvCarouselComponent } from '@styloviz/display/carousel';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Looping with number indicator

example.htmlAngular
<sv-carousel
  [slides]="slides"
  [autoPlay]="true"
  [interval]="5000"
  [loop]="true"
  indicator="numbers"
  aspectRatio="16/9"
  (slideChange)="onSlide($event)"
  (pausedChange)="onPause($event)" />

Calls to action

example.htmlAngular
<!-- slides = [
  { id: 'sale', title: 'Summer sale', image: '/img/sale.webp', cta: 'Shop the sale', ctaLink: '/sale' },
  { id: 'news', title: 'Join the newsletter', cta: 'Subscribe' },
] — a CTA with ctaLink is a link; one without is a button you handle. -->
<sv-carousel [slides]="slides" (ctaClick)="onCta($event)" />

Product images with thumbnails

example.htmlAngular
<sv-carousel [slides]="photos" indicator="thumbnails" />

A row of cards

example.htmlAngular
<!-- three in view, fewer when each would be under 220px wide -->
<sv-carousel [slides]="cards" [slidesPerView]="3" aspectRatio="4/5" [loop]="false" />

Vertical

example.htmlAngular
<sv-carousel [slides]="announcements" orientation="vertical" aspectRatio="21/9" />

When to use

  • Cycling through a small set of images or promotional slides.
  • You want autoplay with arrows and a choice of indicator styles.
  • For browsing many images on demand, use the Image Gallery.

Compare with

  • Media Player — Media Player plays video and audio with a seek bar, captions and a playlist. Carousel is for still slides that advance on a timer or a click.

Async states

  • loading
  • empty
  • error
  • retry

Inputs

NameTypeDefaultDescription
loadingbooleanfalseTrue while the slides are being fetched.
errorSvDataError | string | nullnullLoad failure. Use `toSvDataError()` from `@styloviz/core` to normalize an `HttpErrorResponse`.
emptyMessagestring'No slides to show'Copy for the no-data state.
filteredbooleanfalseTrue when the emptiness is caused by a filter rather than an empty set.
slidesreadonly CarouselSlide[][]Slides to display (image, caption, optional link).
variantCarouselVariant'default'Visual variant. `default` slides full-bleed; `fade` cross-fades in place; `card` insets each slide as a rounded, shadowed card; `coverflow` shows the neighbouring slides scaled down either side of the active one. Under `prefers-reduced-motion` every variant keeps its layout but drops the transition.
indicatorCarouselIndicator'dots'Indicator style: dots, lines, numbers, `thumbnails` (a strip of slide previews under the carousel) or none.
orientationCarouselOrientation'horizontal'Which way the slides travel. `vertical` moves `default` and `card` slides up and down, puts the arrows top and bottom, and takes ↑ / ↓ and vertical swipes. `coverflow` and several slides per view stay horizontal.
slidesPerViewnumber1How many slides show side by side — a row of cards that steps one slide at a time. Fewer show when the carousel is too narrow for each to keep `slideMinWidth`, so a phone sees one. Above 1, `variant` is ignored and `aspectRatio` is each slide's.
slideMinWidthnumber220The narrowest a slide may get when several share the view, in px.
autoPlaybooleanfalseAuto-advance slides.
intervalnumber4000Auto-advance interval in ms.
loopbooleantrueWrap from last slide back to first.
arrowsbooleantrueShow prev/next arrows.
aspectRatiostring'16/9'CSS aspect-ratio for the viewport.
pauseOnHoverbooleantruePause auto-advance while the carousel is hovered or focused.
ariaLabelstring'Carousel'Accessible name for the carousel region.
prioritybooleanfalseLoad the first slide's image eagerly at high fetch priority. Set it when the carousel is above the fold — a hero image is usually the page's Largest Contentful Paint, and a lazy one is fetched only after layout. Later slides stay lazy either way.

Outputs

EventPayload typeDescription
retryvoidThe host should re-run the failed load.
slideChangenumberEmitted with the active slide index when it changes.
pausedChangebooleanEmitted when the user toggles auto-play; payload is the paused state.
ctaClickCarouselSlideEmitted with the slide whose call-to-action was activated (click, Enter or Space). A slide with `ctaLink` still navigates; this fires first, so it suits analytics. A slide without one has no other effect — handle it here.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Bound to the names this component actually exposes.

usage.htmlAngular
<sv-carousel
  [slides]="slides()"
  [loading]="loading()"
  [error]="error()"
  [filtered]="filtered()"
  (retry)="load()"
/>

Host class

Drive the three async inputs from your own fetch.

host.component.tsTypeScript
import { signal } from '@angular/core';
import { toSvDataError, type SvDataError } from '@styloviz/core';
import type { CarouselSlide } from '@styloviz/display/carousel';

readonly slides = signal<CarouselSlide[]>([]);
readonly loading = signal(false);
readonly error = signal<SvDataError | null>(null);
readonly filtered = signal<boolean>(false);

async load(): Promise<void> {
  this.loading.set(true);
  this.error.set(null);
  try {
    const res = await fetch('/api/slides');
    if (!res.ok) throw res;
    this.slides.set(await res.json());
  } catch (e) {
    this.error.set(toSvDataError(e));
  } finally {
    this.loading.set(false);
  }
}
  • This component does not emit a query, so it renders what you give it. Call `load()` on your own trigger and bind `slides`, `loading` and `error`.
  • Set `filtered` when a search or filter is active. It is the difference between "you have no orders" and "no orders match this filter" — telling a customer with 4,000 orders the first one reads as a bug.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • Indicator styles: dots, lines, numbers, thumbnails (a strip of previews under the carousel) or none.
  • Autoplay with configurable interval, `pauseOnHover`, and a built-in pause/play button.
  • Variants: `default` (slide), `fade`, `card` and `coverflow`.
  • `orientation="vertical"` moves `default` and `card` slides up and down (`fade` still cross-fades), with the arrows above and below and the dots down the edge; `coverflow` stays horizontal.
  • `slidesPerView` shows a row of cards that steps one slide at a time and stops with the last in view; each keeps `slideMinWidth` (220px by default), so a narrow container shows fewer. Above 1, `aspectRatio` is each card's and `variant` does not apply.

Best practices

  • Do: Leave `pauseOnHover` on (default) so users can read each slide; a pause/play control also appears during autoplay.
  • Don't: Don't hide important content or CTAs solely inside auto-advancing slides.
  • Tip: Keep slide counts low (3–6); carousels have low engagement past the first slide.

Accessibility

  • Swipe: a horizontal swipe (touch, pen or mouse; 40px or more, and more sideways than up/down) shows the next or previous slide, mirrored under `dir="rtl"`. The region is `touch-pan-y touch-pinch-zoom`, so a vertical swipe still scrolls the page and pinch still zooms it, and the click a swipe ends in is swallowed so a slide's link is not followed by accident. The arrows, dots and ←/→ remain.
  • Exposed as a `region` with `aria-roledescription="carousel"`; slides are labelled groups and a live region announces changes (silenced while auto-rotating).
  • Auto-play pauses on hover and keyboard focus and can be stopped with the pause button (WCAG 2.2.2); ←/→ navigate slides.
  • Prev/next, indicators and pause are labelled buttons; the active indicator exposes `aria-current`.
  • A vertical carousel takes ↑/↓ instead of ←/→ and a vertical swipe instead of a horizontal one; its region is `touch-pan-x`, so a sideways swipe still scrolls.
  • Thumbnails are buttons named by position ("Go to slide 3"), as the dots are; the preview image is decoration (`alt=""`).
  • With several slides in view, every slide in the row is reachable and announced; those outside it are `inert` and hidden from assistive technology, as an inactive slide always is.

Feedback on Carousel

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.