Carousel
Slides travel on a spring and the active dot stretches into a bar.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/carouselThis adds components/keyframery/carousel.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, CarouselViewport } from "@/components/keyframery/carousel"
export default function Usage() {
return (
<Carousel aria-label="Photos">
<CarouselViewport>
<CarouselContent>
<CarouselItem>Slide 1</CarouselItem>
<CarouselItem>Slide 2</CarouselItem>
</CarouselContent>
</CarouselViewport>
<CarouselPrevious />
<CarouselNext />
</Carousel>
)
}Anatomy
How the parts fit together:
Carousel
├── CarouselViewport
│ └── CarouselContent
│ └── CarouselItem
├── CarouselPrevious
└── CarouselNextExamples
Basic
Swipe, drag or use the buttons. Indicators show where you are and jump to a slide.
Autoplay
defaultPlaying advances on its own every interval ms. CarouselPlayToggle pauses it, and CarouselProgress shows the time to the next slide.
Several per page
slidesPerPage shows more than one at a time, for product rows and galleries.
Motion
| Move | What you see |
|---|---|
| Direction | Slides travel on a spring in the direction you moved. |
| Stretch | The active dot widens into a bar. |
| Press | The arrows press in. |
Timing and springiness follow the motion style you set. To change how fast this carousel moves, pass speed:
<Carousel speed="fast">
…
</Carousel>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--carousel-gap | Slide and component spacing | 0.75rem |
--carousel-radius | Viewport corners | 14px |
--carousel-key-size | Arrow key size | 2rem |
--carousel-face | Arrow keys and indicator well | --background (dark --accent) / --muted |
--carousel-ink | Arrow icons, dots and progress | --foreground, opacity 20% / 45% / 10% / 70% by state |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK carousel reference.
Carousel
Renders a <div>, and takes its props too.
Prop
Type
CarouselPrevious
Renders a <button>, and takes its props too.
Prop
Type
CarouselNext
Renders a <button>, and takes its props too.
Prop
Type
CarouselIndicator
Renders a <button>, and takes its props too.
Prop
Type
CarouselIndicatorGroup
Renders a <div>, and takes its props too.
Prop
Type
CarouselPlayToggle
Renders a <button>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
CarouselViewport: a<div>CarouselContent: a<div>CarouselItem: a<div>CarouselProgress: a<div>
Keyboard
| Key | What it does |
|---|---|
| ← | Moves to the previous slide. |
| → | Moves to the next slide. |
| Tab | Moves between the buttons and indicators. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's carousel with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/carousel"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/carousel"Questions
How does the animated Carousel for UI SDK move?
Direction: Slides travel on a spring in the direction you moved. Stretch: The active dot widens into a bar. Press: The arrows press in.
Do I need Motion or Framer Motion for the animated Carousel?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/carousel instead. It has the same parts and props as @ui-sdk/react/carousel and adds motion only.
What happens to the Carousel when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.