carouselcn

Carousel Motion

A carousel component with smooth spring-based animations powered by Motion (Framer Motion).

1
2
3
4

Installation

pnpm dlx shadcn@latest add https://carouselcn.marcellonovelli.com/r/carousel-motion.json

Usage

import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNavigation,
  CarouselIndicator,
} from "@/components/ui/carousel-motion";
<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

Autoplay

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

1
2
3
4

Spring Customization

Customize the spring physics by passing a transition prop to CarouselContent. Adjust stiffness and damping to control the animation feel.

1
2
3
4
300
30

Adjust the spring physics. Higher stiffness = faster animation. Higher damping = less bounce.


API Reference

The root component that provides context for the carousel.

Prop

Type

CarouselContent

Container for carousel items with drag and spring animation 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 Motion (Framer Motion) for spring-based animations. Choose this version if:

  • You want smoother, physics-based animations
  • You need fine-grained control over animation timing (stiffness, damping)
  • You're already using Motion in your project

For a lighter bundle without animation dependencies, consider using Carousel which uses CSS transitions.

On this page