Demos

One slide per view, with previous and next buttons.

Usage

Use a carousel to browse a short set of related items when space is tight, such as biomarker highlights or onboarding steps. Do not hide content the reader must see. Slides past the first are often missed, so put the most important item first. If the reader needs to compare items, use a grid instead.

Import it from @workspace/ui/components/carousel. It is built on Embla Carousel, so every Embla option works through opts.

Anatomy

  • Carousel — The root. Holds the Embla instance and handles arrow keys.
  • CarouselContent — The viewport and the track that slides.
  • CarouselItem — One slide. Full width by default.
  • CarouselPrevious — Button that moves back one slide. Disabled at the start.
  • CarouselNext — Button that moves forward one slide. Disabled at the end.

Notes

  • The buttons sit outside the carousel, 48px from each edge. Leave room for them, or move them with className.
  • Set slide width with a basis-* class on CarouselItem, for example basis-1/3.
  • Spacing between slides comes from ps-4 on each item and -ms-4 on the track. Change both together.
  • For a vertical carousel, give CarouselContent a fixed height.
  • Use useCarousel() inside a child to build custom controls.

Examples

Multiple per view

Use basis-1/2 or basis-1/3 on each item to show more than one slide. opts={{ align: "start" }} lines slides up with the left edge.

With slide counter

Pass setApi to get the Embla API. Listen for select to track the current slide.

Vertical

Set orientation="vertical". The buttons move above and below.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Direction the slides move.
optsEmblaOptionsType—Embla options, such as align and loop.
pluginsEmblaPluginType[]—Embla plugins, such as autoplay.
setApi(api: CarouselApi) => void—Receives the Embla API once it is ready.
classNamestring—Classes merged onto the element.

CarouselPrevious / CarouselNext

PropTypeDefaultDescription
variantButton variant"outline"Button style.
sizeButton size"icon-sm"Button size.
classNamestring—Classes merged onto the button.