Carousel

A row of slides that scrolls and snaps one at a time.

Installation

  1. Add the registryOnce per project
  2. Add carousel

Usage

The carousel uses native scrolling with CSS scroll snapping, so it needs no extra packages. The arrow keys move it one slide at a time while focus is inside it.

Each slide fills the carousel. Give CarouselItem a basis-* class to show more than one, and set --carousel-gap on the carousel to change the space between them.

Give each slide an aria-label such as "2 of 5" so screen readers can say where they are.

Composition

Examples

Several in view

Dots

CarouselDots adds a dot for each position.

Controls below

Placed directly inside the carousel, CarouselPrevious and CarouselNext sit on either side of the slides. Put them in another element to lay them out yourself, such as in a row with the dots.

Vertical

Set orientation="vertical" to scroll up and down, and give CarouselContent a height.

Props

useCarousel() gives your own parts inside the carousel its state and controls: index, count, canScrollPrev, canScrollNext, scrollTo(index), scrollPrev() and scrollNext().

CarouselPrevious

CarouselNext