Skip to content
Ballpoint

Carousel

Slides in a row or a column that you drag, swipe, scroll or step through, snapping into place. No library: it is the browser's own scroll snapping.

From shadcn/ui
1
2
3
4
5

Installation

pnpm dlx shadcn@latest add @ballpoint/carousel

Usage

tsx
import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel"

<Carousel>
  <CarouselContent>
    <CarouselItem>…</CarouselItem>
    <CarouselItem>…</CarouselItem>
  </CarouselContent>
  <CarouselPrevious />
  <CarouselNext />
</Carousel>

Examples

Slides narrower than the row, several in view at once.

1
2
3
4
5
6
7

A column of slides, with the arrows above and below.

1
2
3
4

setApi hands you the controls: dots, a position, a loop.

1
2
3
4
5

API reference

orientation
default "horizontal"
"horizontal" | "vertical"

Which way the slides run.

opts
{ align?: 'start' | 'center' | 'end'; loop?: boolean }

Where the chosen slide rests, and whether the ends wrap round.

setApi
(api: CarouselApi) => void

Called with scrollPrev, scrollNext, scrollTo, canScrollPrev, canScrollNext, selectedScrollSnap, scrollSnapList, on and off.

CarouselItem className
string

Set the slide's width: basis-1/2, basis-1/3.