Skip to content
UI

Search docs

Search components and documentation

New
Menu

Carousel

A carousel of slides with previous/next controls and keyboard navigation.

Installation

npx logic2b@latest add carousel

Usage

import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel"

<Carousel>
  <CarouselContent>
    <CarouselItem>1</CarouselItem>
    <CarouselItem>2</CarouselItem>
    <CarouselItem>3</CarouselItem>
  </CarouselContent>
  <CarouselPrevious />
  <CarouselNext />
</Carousel>

Built on embla-carousel-react — pass embla options via the opts prop and plugins via plugins, or get the imperative API with setApi.

API

Prop Type Default
orientation (Carousel) horizontal | vertical horizontal
opts (Carousel) Embla EmblaOptionsType
plugins (Carousel) Embla plugins array
setApi (Carousel) (api: CarouselApi) => void

CarouselPrevious and CarouselNext accept the standard Button props (variant, size) and are automatically disabled at the ends.

Examples

Multiple items

Set the basis of each CarouselItem to show several slides at once.

Vertical

Use orientation="vertical" to scroll slides top to bottom.

Accessibility

  • The root has role="region" with aria-roledescription="carousel", and each slide is a role="group" labelled as a slide.
  • When the carousel is focused, Arrow Left and Arrow Right scroll to the previous/next slide.
  • The previous/next buttons include sr-only labels and become disabled when there is nothing more to scroll to.