Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Carousel for React

An interactive slideshow for cycling through items.

1
2
3
4
5

Installation

bunx --bun shadcn@latest add https://kit.dev/r/aria/carousel.json

Anatomy

Carousel
├── CarouselItem
│   └── CarouselContent
├── CarouselControl
├── CarouselNext
├── CarouselPrevious
├── CarouselIndicator
│   └── CarouselIndicatorGroup
├── CarouselAutoplayTrigger
└── CarouselProgressText

Usage

import { Card, CardContent } from "@/components/ui/card";
import {
  Carousel,
  CarouselContent,
  CarouselControl,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel";
const slides = [1, 2, 3, 4, 5];

const CarouselDemo = () => (
  <Carousel
    className="w-full max-w-[12rem] sm:max-w-xs"
    slideCount={slides.length}
  >
    <CarouselContent>
      {slides.map((slide, index) => (
        <CarouselItem index={index} key={slide}>
          <div className="p-1">
            <Card>
              <CardContent className="flex aspect-square items-center justify-center p-6">
                <span className="font-semibold text-4xl">{slide}</span>
              </CardContent>
            </Card>
          </div>
        </CarouselItem>
      ))}
    </CarouselContent>
    <CarouselControl>
      <CarouselPrevious />
      <CarouselNext />
    </CarouselControl>
  </Carousel>
);

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.
ArrowDown
Move to the next item.
ArrowUp
Move to the previous item.
ArrowRight
Move to the next item.
ArrowLeft
Move to the previous item.
Home
Go to the start.
End
Go to the end.

Demos

Size

Set item size with slidesPerPage (Ark equivalent of Embla basis-*).

Spacing

Control the gap between slides with the spacing prop.

Orientation

Use orientation="vertical" for a vertical carousel.

Api

Track the current page with controlled page / onPageChange.

Plugin

Autoplay with pause on hover via Ark autoplay / pause / play.

Multiple

Show multiple slides per page with slidesPerPage.

Rtl

Right-to-left carousel. See the RTL configuration guide for document direction.

API Reference