Skip to content
Playground

Carousel

A compound carousel powered by Embla with responsive sizing, orientation, controls, and accessible semantics.

Carousel presents a sequence of related content in a swipeable viewport. Use it when horizontal or vertical browsing is more useful than showing every item at once; do not hide essential content behind a carousel when a list or grid would be easier to scan.

Powered by Embla Carousel for drag gestures, snapping, direction, and loop behavior. Zenos owns the compound anatomy, controls, dots, states, and accessible semantics.

pnpm dlx @zentara-co/zenos-cli add carousel

The command installs embla-carousel-react and adds carousel.tsx to the consumer project. Import the recipe through the path configured by your application:

TSX
import { Carousel } from "./components/carousel";

Compose Root, Viewport, Content, and Item first, then add Previous, Next, or Dots where the product needs explicit navigation.

Carousel.Root
├── Carousel.Viewport
│   └── Carousel.Content
│       ├── Carousel.Item
│       └── Carousel.Item
├── Carousel.Previous
├── Carousel.Next
└── Carousel.Dots

Carousel.Root owns Embla state and provides it to every compound part. Viewport is the clipped drag surface, Content is the moving flex track, and each Item is one accessible slide.

Items default to basis-full, so one slide occupies the viewport. Override the item basis to show multiple slides. Responsive basis values let the same carousel show one item on narrow screens and more items when space permits.

Keep enough of the next item visible—or provide enabled controls and dots—so users can discover that more content exists.

The recipe defaults to a 16px gap using a negative inline margin on Content and matching start padding on Item. For a visually centered group, remove the track offset and split the desired gap evenly across both sides of every Item.

The example uses marginInlineStart: 0 on Content and 12px inline padding on each side of Item, producing a centered 24px gap. Use logical paddingInline or paddingBlock so the same layout works with RTL and vertical orientation.

Set orientation="vertical", give Viewport an explicit height, and size items relative to that height. The recipe switches the track axis and touch-action behavior automatically.

Previous and Next are intentionally composable. The example places them outside the viewport and rotates the default chevrons so their visual direction matches the vertical axis.

loop wraps navigation from the last snap to the first. slidesToScroll advances more than one slide per navigation action. Use grouped movement when the visible items form a meaningful page.

Avoid looping when users need a clear sense of completion. When looping is enabled, controls remain available because either direction always has another snap.

Previous and Next are Zenos IconButtons. They disable automatically at their respective boundary when loop is false. Consumer onClick handlers run before carousel navigation and can cancel movement with event.preventDefault().

Dots are derived from Embla’s snap list, not directly from the number of Item elements. This matters when multiple items share a snap or slidesToScroll groups them. The active dot uses aria-current="true", and every dot has a Go to slide N label.

You can omit controls, dots, or both. If drag is the only visible interaction, ensure the surrounding product still makes the additional content discoverable.

Pass dir="rtl" to Root. The recipe forwards the direction to Embla and uses logical spacing for the horizontal track.

TSX
<Carousel.Root dir="rtl" aria-label="تقارير الأمان">  <Carousel.Viewport>    <Carousel.Content>      {reports.map((report) => (        <Carousel.Item key={report.id}>{report.title}</Carousel.Item>      ))}    </Carousel.Content>  </Carousel.Viewport>  <Carousel.Previous className="rtl:rotate-180" />  <Carousel.Next className="rtl:rotate-180" /></Carousel.Root>

Rotate the built-in chevrons when their visual direction should mirror with the interface. Custom icons can encode their own direction instead.

PropTypeDefaultDescription
orientation 'horizontal' | 'vertical' horizontal Slide axis and track layout.
align 'start' | 'center' | 'end' start Embla snap alignment inside the viewport.
loop boolean false Wraps navigation between the final and first snaps.
slidesToScroll number 1 Number of slides advanced by Previous or Next.
dir 'ltr' | 'rtl' ltr Reading and Embla movement direction.
aria-label string — Accessible name for the carousel region.
className / native div props string / HTMLAttributes<HTMLDivElement> — Styles or labels the root region.
PropTypeDefaultDescription
Viewport.className string — Viewport sizing and layout overrides; overflow remains clipped by default.
Content.className string — Track spacing and flex-layout overrides.
Item.className string — Slide basis, spacing, and responsive sizing.
Previous / Next.disabled boolean — Consumer-disabled state combined with the current Embla boundary state.
Previous / Next.onClick MouseEventHandler<HTMLButtonElement> — Runs before movement; prevent default to cancel carousel navigation.
Previous / Next.children ReactNode — Replaces the built-in directional icon.
Dots.className string — Styles the snap-navigation container.

All parts forward their native HTML attributes and refs to the rendered element.

The Zenos recipe exposes a focused set of Embla options as typed Root props rather than exposing the raw Embla API. There is no setApi, opts, or plugins prop in the current public contract.

Because recipes are consumer-owned, extend the local carousel.tsx only when the product has a concrete requirement. For example, autoplay requires installing embla-carousel-autoplay and supplying the plugin in the recipe’s useEmblaCarousel call:

TSX
import Autoplay from "embla-carousel-autoplay"; const autoplay = Autoplay({ delay: 4000, stopOnInteraction: true });const [carouselRef, api] = useEmblaCarousel(options, [autoplay]);

Pause autoplay while the carousel or its controls have focus or pointer hover, and disable automatic movement when the user prefers reduced motion. Avoid adding plugin dependencies to @zentara-co/zenos-ui; they belong to this specialist recipe.

If product logic needs selection events, prefer adding a focused callback such as onSelectedIndexChange to the local recipe over leaking the full Embla instance through unrelated feature components.

The recipe provides region, carousel, slide, control, and active-dot semantics. Complete the accessible experience in consumer code:

  • Give Root a concise aria-label or aria-labelledby.
  • Keep Previous, Next, and Dots keyboard reachable when they are rendered.
  • Put meaningful interactive content inside Item without intercepting its native keyboard behavior.
  • Do not move focus when the active slide changes; users should retain control of navigation.
  • Announce automatic slide changes only when the product genuinely requires them, and provide a pause control.
  • Preserve sufficient contrast for controls placed over media.