Installation
npx logic2b@next add carouselUsage
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.
Usage notes
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"witharia-roledescription="carousel", and each slide is arole="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-onlylabels and becomedisabledwhen there is nothing more to scroll to.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
<Carousel
orientation="horizontal"
className="w-full max-w-xs"
aria-label="Registry highlights"
>
<CarouselContent
className="h-44"
>
<CarouselItem>
<div
className="flex h-40 items-center justify-center rounded-lg border bg-muted text-3xl font-semibold"
>1</div>
</CarouselItem>
<CarouselItem>
<div
className="flex h-40 items-center justify-center rounded-lg border bg-muted text-3xl font-semibold"
>2</div>
</CarouselItem>
<CarouselItem>
<div
className="flex h-40 items-center justify-center rounded-lg border bg-muted text-3xl font-semibold"
>3</div>
</CarouselItem>
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>API reference
Generated from the public TypeScript exports in src/ui/carousel.tsx.
CarouselApi
Typetype CarouselApi = UseEmblaCarouselType[1]Carousel
ComponentProps: React.ComponentProps<"div"> & CarouselProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
orientation | "horizontal" | "vertical" | No | "horizontal" | — |
opts | CarouselOptions | No | — | — |
setApi | (api: CarouselApi) => void | No | — | — |
plugins | CarouselPlugin | No | — | — |
CarouselContent
ComponentProps: React.ComponentProps<"div">CarouselItem
ComponentProps: React.ComponentProps<"div">CarouselPrevious
ComponentProps: React.ComponentProps<typeof Button>| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | null | "link" | "default" | "destructive" | "secondary" | "outline" | "ghost" | No | "outline" | — |
size | null | "default" | "sm" | "lg" | "icon" | No | "icon" | — |
CarouselNext
ComponentProps: React.ComponentProps<typeof Button>| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | null | "link" | "default" | "destructive" | "secondary" | "outline" | "ghost" | No | "outline" | — |
size | null | "default" | "sm" | "lg" | "icon" | No | "icon" | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for carousel.
- Support
- Authored behavior
- Pattern
- carousel
- Embla Carousel
| Keys | Behavior |
|---|---|
| ArrowLeft ArrowRight | Move to the previous or next slide. |
| Tab | Reach the explicit previous/next buttons. |
Built-in semantics
- The root is a labelled carousel region; slides are labelled groups and controls expose names/disabled state.
Consumer responsibilities
- Give the carousel a contextual aria-label and avoid auto-rotation without a pause control.