carouselcn

Carousel

A lightweight carousel component with CSS transitions and drag support. No additional animation library required.

1
2
3
4

Installation

pnpm dlx shadcn@latest add https://carouselcn.vercel.app/r/carousel.json
or

If you are using a namespaced registry, you can use the following command:

pnpm dlx shadcn@latest add @carouselcn/carousel

Usage

import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNavigation,
  CarouselIndicator,
} from "@/components/ui/carousel";
<Carousel>
  <CarouselContent>
    <CarouselItem>Slide 1</CarouselItem>
    <CarouselItem>Slide 2</CarouselItem>
    <CarouselItem>Slide 3</CarouselItem>
  </CarouselContent>
  <CarouselNavigation />
  <CarouselIndicator />
</Carousel>

Examples

Basic

1
2
3
4

Custom Indicator

Use controlled state with index and onIndexChange to build custom indicators.

1
2
3
4

Loop

Enable looping with the loop prop. When reaching the last slide, navigating forward jumps back to the first slide.

1
2
3
4

Vertical

Use orientation="vertical" for vertical sliding. The container must have an explicit height.

1
2
3
4

Sizes and Spacing

Use -ml-4 on CarouselContent and pl-4 on CarouselItem to add spacing between items. Use basis-1/3 (or other values) to show multiple items at once.

1
2
3
4
5
6
7

Use className on CarouselNavigation to reposition the navigation buttons anywhere you want.

1
2
3
4

Custom Navigation

Use the useCarousel hook to build completely custom navigation elements.

1
2
3
4
1 / 0

Autoplay

Use the useCarouselAutoplay hook to automatically advance slides. The hook provides play, pause, and toggle controls.

1
2
3
4

API Reference

The root component that provides context for the carousel.

Prop

Type

CarouselContent

Container for carousel items with drag and transition support.

Prop

Type

CarouselItem

Individual slide wrapper.

Prop

Type

CarouselNavigation

Previous/next navigation buttons.

Prop

Type

CarouselIndicator

Dot indicators showing current slide position.

Prop

Type

useCarousel

Hook to access carousel state and controls.

const { index, setIndex, itemsCount } = useCarousel();

useCarouselAutoplay

Hook to enable automatic slide advancement.

const { isPlaying, play, pause, toggle } = useCarouselAutoplay({
  interval: 3000,
  autoStart: true,
});

Prop

Type

Returns:

Prop

Type


This component uses CSS transitions instead of Motion (Framer Motion). Choose this version if:

  • You want a smaller bundle size
  • You don't need spring-based animations
  • You're not already using Motion in your project

For smoother, spring-based animations, consider using Carousel Motion.

On this page