A server-rendered carousel on native CSS scroll-snap. Slides swipe and snap by themselves, the dots and image thumbnails are links to the slides, and the focused track scrolls with the arrow keys, all without JavaScript. A client script of about 1 kB enables the arrow buttons, marks the active dot, updates the counter and progress bar and runs auto-play.
Browser Support
Aligns items while scrolling
Tracks the current scroll target
Creates scroll controls
Adapts controls to JavaScript availability
Colors the CSS scroll buttons
Hides the scrollbar
Contains scroll gestures
Installation
Usage
import {
Carousel,
CarouselItem,
CarouselPrevious,
CarouselNext,
CarouselDots,
} from "@/components/ui/carousel"
export default function Example() {
return (
<Carousel>
<CarouselItem>Slide 1</CarouselItem>
<CarouselItem>Slide 2</CarouselItem>
<CarouselItem>Slide 3</CarouselItem>
<CarouselPrevious />
<CarouselNext />
<CarouselDots />
</Carousel>
)
}Examples
With Progress Bar





<Carousel>
{items.map((item) => (
<CarouselItem key={item.id}>{item.content}</CarouselItem>
))}
<CarouselPrevious />
<CarouselNext />
<div className="mt-4 space-y-2">
<CarouselProgress />
<CarouselCounter />
</div>
</Carousel>Multiple Items





<CarouselItem size="1/3">
{/* Shows 3 items at once */}
</CarouselItem>Auto-Play with Loop
Auto-play pauses on hover and on keyboard focus and does not start when the user prefers reduced motion.
<Carousel autoPlay={3000} loop>
{/* Auto-advances every 3 seconds */}
</Carousel>Vertical





<Carousel orientation="vertical" className="h-[400px]">
{/* Vertical scrolling */}
</Carousel>Thumbnails
CarouselThumbnails adds a strip of image links under, left or right of the slides, the way product galleries do. Each thumbnail is a link to its slide, so it works without JavaScript. The client script marks the active thumbnail and keeps it in view as the strip scrolls. With a single slide the strip is not rendered.
Product gallery
const images = [
{ src: "/photos/1.webp", thumbnail: "/photos/1-thumb.webp", alt: "Front view" },
{ src: "/photos/2.webp", thumbnail: "/photos/2-thumb.webp", alt: "Side view" },
{ src: "/photos/3.webp", thumbnail: "/photos/3-thumb.webp", alt: "Back view" },
]
<Carousel>
{images.map((image) => (
<CarouselItem key={image.src}>
<img src={image.src} alt={image.alt} className="aspect-[4/3] w-full rounded-xl object-cover" />
</CarouselItem>
))}
<CarouselPrevious />
<CarouselNext />
<CarouselThumbnails images={images} />
</Carousel>Props
Carousel
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | "horizontal" | "vertical" | "horizontal" | Scroll direction |
| loop | boolean | false | Arrows jump from the last slide to the first and back |
| autoPlay | number | 0 | Auto-play interval in ms, 0 turns it off |
| pauseOnHover | boolean | true | Pause auto-play while the pointer is over the carousel |
| draggable | boolean | - | Kept for compatibility, has no effect |
CarouselItem
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "full" | "1/2" | "1/3" | "1/4" | "auto" | "full" | Item width |
CarouselPrevious / CarouselNext
| Prop | Type | Default | Description |
|---|---|---|---|
| iconSize | number | 16 | Size of the default chevron icon |
| children | ReactNode | - | Custom button content instead of the chevron |
CarouselThumbnails
| Prop | Type | Default | Description |
|---|---|---|---|
| images | { src: string; alt?: string; thumbnail?: string }[] | - | One entry per slide: src, alt and an optional smaller thumbnail image |
| position | "bottom" | "left" | "right" | "bottom" | Where the strip sits, left and right make it vertical |
| slideLabel | (index: number) => string | Go to slide N | Accessible name of each dot or thumbnail link |
CarouselDots
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "dots" | "line" | "numbers" | "dots" | Indicator style |
| slideLabel | (index: number) => string | Go to slide N | Accessible name of each dot or thumbnail link |
Features
- Server component: markup and dots are rendered on the server, only the controller is client code
- CSS Scroll Snap: native swipe and snapping, no scroll math in JS
- Dot links: every dot is an anchor to its slide and works without JS
- Keyboard: the track is focusable, arrow keys scroll it
- Indicators: dots, lines, numbers, progress bar and counter
- Thumbnails: image strip below or beside the slides, replaces a separate gallery component
- Reduced motion: smooth scrolling and auto-play are off when the user asks for less motion
Migration
- useCarousel is removed: Carousel is a server component now and has no React context
- Dots are links with aria-current instead of tab buttons
- Dots, progress and counter must sit inside Carousel or inside plain elements in it
- draggable no longer does anything (it was a no-op before as well)
- Thumbnail Gallery is merged into Carousel: use CarouselThumbnails with images and position instead of ThumbnailGallery