This page as markdown: /carousel.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

Carousel

Status: stable

Generic, accessible, zero-dependency slide carousel. Transform track with measured slide pitch — multiple slides per view, infinite loop (cloned ends), pointer drag-to-swipe with snap, autoplay (with a pause control + hover/focus/reduced-motion pausing), arrows, dots, counter, and keyboard. Motion is token-driven.

Keywords: carousel, gallery, slides, horizontal

Usage

Use Carousel for a curated, finite sequence of media or cards that benefits from horizontal browsing.

Best practices

Props

Name Type Default Description
children ReactNode — Each top-level child becomes one slide.
slidesToShow number | { base?: number; sm?: number; md?: number; lg?: number; xl?: number } 1 Slides visible per view. A number, or a smallest-first width set (sm 640, md 768, lg 1024, xl 1280px) measured on the carousel's OWN width, not the viewport, so a carousel in a narrow column shows fewer slides than one across the page; a missing key inherits from the next smaller defined one, and base (default 1) is also the server-render value.
gap string "0px" Gap between slides (any CSS length). Use the spacing scale — e.g. "calc(var(--spacing) * 4)" — so density moves it.
loop boolean false Infinite loop via cloned ends (needs count > slidesToShow).
autoplay number 0 Auto-advance interval in ms (0 = off). Pauses on hover/focus/reduced-motion and exposes a play/pause control.
arrows boolean true Prev/next arrow buttons.
dots boolean true Pagination dots.
counter boolean false An N / M slide counter.
draggable boolean true Pointer drag-to-swipe.
index number — Controlled active index.
defaultIndex number 0 Initial index (uncontrolled).
onIndexChange (index: number) => void — Notified when the active index changes.
label string "Slides" Accessible label for the carousel region.
previousLabel string "Previous slide" The previous arrow's accessible name.
nextLabel string "Next slide" The next arrow's accessible name.
slideLabel (index: number, count: number) => string (index, count) => ${index} of ${count} Each slide's accessible name, from its 1-based position.
positionLabel (index: number, count: number) => string (index, count) => Slide ${index} of ${count} What the polite live region announces after a move, from the 1-based position.
dotsLabel string "Choose slide" The dots group's accessible name.
dotLabel (index: number) => string (index) => Go to slide ${index} Each dot's accessible name, from its 1-based slide number.
pauseLabel string "Pause autoplay" The autoplay toggle's name while playing.
playLabel string "Start autoplay" The autoplay toggle's name while paused.
slideClassName string — Class for each slide wrapper (e.g. an aspect ratio).
arrowClassName string — Class for both prev/next arrow buttons. Merged through cn(), so a radius or shadow utility replaces the default rounded-full shadow-md rather than stacking with it.
motion "full" | "subtle" | "off" "full" How much motion this component uses: full (default) inherits the app's policy, subtle keeps feedback and drops the glide, off stills it. It can only turn motion down — it never overrides a reader's reduce-motion setting. Under subtle the slides still travel and the active dot snaps; off also cuts between slides and pauses autoplay.

Tokens used

border, ring, popover, popover-foreground, foreground, muted-foreground

Motion

Accessibility

Related

Examples

Looping media

import { Carousel } from "@sableui/react"

<Carousel loop dots slideClassName="aspect-video">{images.map((s) => <img key={s.id} src={s.url} alt={s.alt} className="size-full object-cover" />)}</Carousel>

Multiple per view

import { Carousel } from "@sableui/react"

<Carousel slidesToShow={3} gap="calc(var(--spacing) * 4)">{cards}</Carousel>

Responsive per view

import { Carousel } from "@sableui/react"

<Carousel slidesToShow={{ base: 1, sm: 2, lg: 3 }} gap="calc(var(--spacing) * 6)" label="Templates">{cards}</Carousel>

Autoplay

import { Carousel } from "@sableui/react"

<Carousel loop autoplay={4000} counter>{slides}</Carousel>

Subtle motion

import { Carousel } from "@sableui/react"

<Carousel loop motion="subtle" label="Gallery">{slides}</Carousel>