Carousel
Web/MobileA carousel with motion and swipe built on Embla.
Installation
pnpm dlx cubix-ui@latest add carousel --base radixUsage
import { Card, CardContent } from "@/components/cubix/card"
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselNext,
CarouselPrevious,
} from "@/components/cubix/carousel"
const slides = ["۱", "۲", "۳", "۴", "۵"]
function Slide({ label }: { label: string }) {
return (
<div className="p-1">
<Card className="py-0">
<CardContent className="flex aspect-square items-center justify-center p-6">
<span className="text-4xl font-semibold">{label}</span>
</CardContent>
</Card>
</div>
)
}
<div className="p-1">
<Card className="py-0">
<CardContent className="flex aspect-square items-center justify-center p-6">
<span className="text-4xl font-semibold">{label}</span>
</CardContent>
</Card>
</div>
)
}
export function CarouselDemo() {
return (
<div className="mx-auto w-full max-w-xs px-12">
<Carousel>
<CarouselContent>
{slides.map((label) => (
<CarouselItem key={label}>
<Slide label={label} />
</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>
</div>
Composition
Leave room for the previous and next buttons with horizontal padding on the wrapper. The carousel reads dir from the closest ancestor and defaults to rtl.
Carousel
├── CarouselContent
│ ├── CarouselItem
│ └── CarouselItem
├── CarouselPrevious
└── CarouselNextAccessibility
The root is a focusable region with aria-roledescription="carousel". Each item is a group with aria-roledescription="slide". Nav buttons expose Persian screen-reader labels and disable at the ends unless looping.
| Key | Action |
|---|---|
| ArrowLeft / ArrowRight | On the carousel region, move to the previous or next slide in reading direction. In RTL, ArrowLeft goes to the next slide. |
Examples
Sizes
Set slide width with basis utilities such as md:basis-1/2 and lg:basis-1/3.
Spacing
Override the default gap by changing the negative margin on CarouselContent and the matching padding on CarouselItem.
Orientation
Set orientation="vertical" and give the content a fixed height so slides stack and scroll on the y axis.
API
Pass setApi to read the Embla instance and show the current slide index.
API Reference
Note: Parts render data-slot attributes (carousel, carousel-content, carousel-item, carousel-previous, carousel-next) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
Carousel
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | "horizontal" | "vertical" | "horizontal" | Scroll axis of the carousel. |
| opts | EmblaOptions | - | Embla options such as loop, align, and direction. Defaults to rtl when the closest dir on the page is rtl or missing, matching Cubix Persian-first layout. |
| plugins | EmblaPlugin[] | - | Embla plugins such as Autoplay. |
| setApi | (api: CarouselApi) => void | - | Receive the Embla API instance for events and programmatic scroll. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
CarouselItem
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Use basis utilities such as basis-1/2 or md:basis-1/3 to set slide width. |
CarouselPrevious / CarouselNext
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "foreground" | "secondary" | "gray" | "destructive" | "destructive-secondary" | "outline" | "ghost" | "link" | "outline" | Visual style of the previous or next button. |
| size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-sm" | Size of the previous or next button. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |