Carousel

A row of slides people step through, one or a few at a time.

import { Carousel, CarouselSlide } from '@halo-ds/react';

When to use it

Carousel shows slides in a row with Previous and Next buttons on the sides and dots below. People swipe, scroll, click or use the arrow keys. It never moves on its own, so nobody loses their place. A slide can hold an image, a Card or any content.

Do

  • Keep it to a few slides, about 3 to 7.
  • Show part of what each slide is about, so people know if it's worth a look.
  • Give it a name for screen readers, like Featured courses.
  • Show the arrows on larger screens; not everyone can swipe.

Don't

  • Move the slides on their own; people lose their place.
  • Put the only copy of important information on slide 3.
  • Use dots alone for 10 or more slides.
  • Nest a carousel inside another one.

Props

Carousel props

PropTypeWhat it does
aria-label (required)stringNames the carousel for screen readers, like "Featured courses".
children (required)ReactNodeCarouselSlide elements.
slidesPerView`number \undefined`Slides visible at once. Default 1.
showArrows`boolean \undefined`Previous and next buttons on the sides. Figma: Arrows.
showDots`boolean \undefined`A dot for each position under the slides. Figma: Dots.
onIndexChange`((index: number) => void) \undefined`Called with the index of the first visible slide.
classNames`Partial<Record<CarouselPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<CarouselPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

CarouselSlide props

PropTypeWhat it does
children (required)ReactNode

It also takes the usual HTML attributes for its element.

Examples

Overview

import { Carousel, CarouselSlide } from '@halo-ds/react';

const slides = [
  { title: 'Plan', color: '#c9daff' },
  { title: 'Build', color: '#f3c8f4' },
  { title: 'Launch', color: '#b9e6ce' },
];

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 520 }}>
      <Carousel aria-label="Highlights">
        {slides.map((s) => (
          <CarouselSlide key={s.title}>
            <div style={{ display: 'grid', placeItems: 'center', aspectRatio: '16 / 9', borderRadius: 16, background: s.color, color: '#0c0c0c', fontSize: 24, fontWeight: 600 }}>
              {s.title}
            </div>
          </CarouselSlide>
        ))}
      </Carousel>
    </div>
  );
}

Several at a time

Cards, three at a time, with arrows to move along.

import { Card, Carousel, CarouselSlide, Text } from '@halo-ds/react';

const courses = ['Design basics', 'Colour theory', 'Typography', 'Layout grids', 'Motion'];

export default function Demo() {
  return (
    <div style={{ width: '100%' }}>
      <Carousel aria-label="Courses" slidesPerView={3}>
        {courses.map((c) => (
          <CarouselSlide key={c}>
            <Card>
              <Text weight="semibold">{c}</Text>
              <Text size="sm" color="secondary">6 lessons</Text>
            </Card>
          </CarouselSlide>
        ))}
      </Carousel>
    </div>
  );
}

Dots only

No arrows: people swipe or use the dots.

import { Carousel, CarouselSlide } from '@halo-ds/react';

const slides = ['#c9daff', '#f3c8f4', '#b9e6ce'];

export default function Demo() {
  return (
    <div style={{ width: '100%', maxWidth: 480 }}>
      <Carousel aria-label="Highlights" showArrows={false}>
        {slides.map((color, i) => (
          <CarouselSlide key={color}>
            <div style={{ display: 'grid', placeItems: 'center', aspectRatio: '16 / 9', borderRadius: 16, background: color, color: '#0c0c0c', fontWeight: 600 }}>
              Slide {i + 1}
            </div>
          </CarouselSlide>
        ))}
      </Carousel>
    </div>
  );
}

More: https://halodesignsystem.dev/components/carousel