Carousel

Web/Mobile

A carousel with motion and swipe built on Embla.

۱
۲
۳
۴
۵

Installation

pnpm dlx cubix-ui@latest add carousel

Usage

Import
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>
  )
}
Example
<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.

Structure
Carousel
├── CarouselContent
│   ├── CarouselItem
│   └── CarouselItem
├── CarouselPrevious
└── CarouselNext

Accessibility

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.

KeyAction
ArrowLeft / ArrowRightOn 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

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Scroll axis of the carousel.
optsEmblaOptions-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.
pluginsEmblaPlugin[]-Embla plugins such as Autoplay.
setApi(api: CarouselApi) => void-Receive the Embla API instance for events and programmatic scroll.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

CarouselItem

PropTypeDefaultDescription
classNamestring-Use basis utilities such as basis-1/2 or md:basis-1/3 to set slide width.

CarouselPrevious / CarouselNext

PropTypeDefaultDescription
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.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).