Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Data display

Carousel

Free19.1 KB gzipped

A row of slides that scroll horizontally with CSS scroll snap (so touch, trackpad, and swipe work natively), plus Previous / Next buttons, optional slide picker indicators, and optional autoplay with a Pause / Play button. Follows the WAI-ARIA APG carousel pattern: a named <section> with aria-roledescription="carousel", and slides as role="group" with aria-roledescription="slide". Slides fully out of view are inert.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Arrow Right, Arrow Left and 4 more · Full report

Import

tsx
import { Carousel } from "@vjdesigns/vjdesigns-ui";

Importing only Carousel adds about 19.1 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Basic

Previous and next buttons, swipe and the arrow keys move between slides. Each slide is announced as "1 of 3".

Slide 1 of 3
Purple mountains at dusk
A sandy beach beside a calm sea
A dense pine forest
tsx
import { Carousel, Image } from "@vjdesigns/vjdesigns-ui";

const scenes = [
  { src: "/docs/mountains.svg", alt: "Purple mountains at dusk", title: "Mountains" },
  { src: "/docs/coast.svg", alt: "A sandy beach beside a calm sea", title: "Coast" },
  { src: "/docs/forest.svg", alt: "A dense pine forest", title: "Forest" },
];

export function Basic() {
  return (
    <div style={{ width: "100%", maxWidth: "34rem" }}>
      <Carousel aria-label="Destinations" indicators loop>
        {scenes.map((scene) => (
          <Carousel.Slide key={scene.title}>
            <Image src={scene.src} alt={scene.alt} ratio="landscape" />
          </Carousel.Slide>
        ))}
      </Carousel>
    </div>
  );
}

Multiple slides

slidesPerView accepts one value or one per breakpoint.

Slide 1 of 6
Purple mountains at dusk

Mountains trip 1

A sandy beach beside a calm sea

Coast trip 2

A dense pine forest

Forest trip 3

Purple mountains at dusk

Mountains trip 4

A sandy beach beside a calm sea

Coast trip 5

A dense pine forest

Forest trip 6

tsx
import { Card, Carousel, Image, Text } from "@vjdesigns/vjdesigns-ui";

const scenes = [
  { src: "/docs/mountains.svg", alt: "Purple mountains at dusk", title: "Mountains" },
  { src: "/docs/coast.svg", alt: "A sandy beach beside a calm sea", title: "Coast" },
  { src: "/docs/forest.svg", alt: "A dense pine forest", title: "Forest" },
];

export function MultipleSlides() {
  return (
    <div style={{ width: "100%" }}>
      <Carousel aria-label="Featured trips" slidesPerView={{ base: 1, md: 2 }} gap={4} controlsPlacement="bottom">
        {[...scenes, ...scenes].map((scene, i) => (
          <Carousel.Slide key={i}>
            <Card variant="outline" padding="sm">
              <Image src={scene.src} alt={scene.alt} ratio="video" radius="md" />
              <Text weight="semibold">
                {scene.title} trip {i + 1}
              </Text>
            </Card>
          </Carousel.Slide>
        ))}
      </Carousel>
    </div>
  );
}

Accessibility

With autoplay, a Pause / Play button is the first control. Rotation pauses on hover, stops when keyboard focus enters, and doesn't start on its own for people who prefer reduced motion (SC 2.2.2). Slides out of view are inert, so Tab never lands on hidden content.

Slide 1 of 3
Purple mountains at dusk
A sandy beach beside a calm sea
A dense pine forest
tsx
import { Carousel, Image } from "@vjdesigns/vjdesigns-ui";

const scenes = [
  { src: "/docs/mountains.svg", alt: "Purple mountains at dusk", title: "Mountains" },
  { src: "/docs/coast.svg", alt: "A sandy beach beside a calm sea", title: "Coast" },
  { src: "/docs/forest.svg", alt: "A dense pine forest", title: "Forest" },
];

export function Accessibility() {
  return (
    <div style={{ width: "100%", maxWidth: "34rem" }}>
      <Carousel aria-label="Featured trips" autoplay interval={6000} indicators loop>
        {scenes.map((scene) => (
          <Carousel.Slide key={scene.title} label={scene.title}>
            <Image src={scene.src} alt={scene.alt} ratio="landscape" />
          </Carousel.Slide>
        ))}
      </Carousel>
    </div>
  );
}

Translated

In Arabic the carousel runs right to left, and the control names and "slide 1 of 3" announcements come from the locale.

الشريحة 1 من 3
Purple mountains at dusk
A sandy beach beside a calm sea
A dense pine forest
tsx
import { Carousel, Image, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

const scenes = [
  { src: "/docs/mountains.svg", alt: "Purple mountains at dusk", title: "Mountains" },
  { src: "/docs/coast.svg", alt: "A sandy beach beside a calm sea", title: "Coast" },
  { src: "/docs/forest.svg", alt: "A dense pine forest", title: "Forest" },
];

export function Translated() {
  return (
    <LocaleProvider locale="ar" messages={ar}>
      <div style={{ width: "100%", maxWidth: "34rem" }}>
        <Carousel aria-label="وجهات" indicators>
          {scenes.map((scene) => (
            <Carousel.Slide key={scene.title}>
              <Image src={scene.src} alt={scene.alt} ratio="landscape" />
            </Carousel.Slide>
          ))}
        </Carousel>
      </div>
    </LocaleProvider>
  );
}

API reference

Carousel props
PropTypeDefault
children

The slides: Carousel.Slide elements. Fragments are flattened, so each slide counts on its own.

ReactNode—
index

Controlled index of the current (leading) slide, 0-based.

number—
defaultIndex

Initial index when uncontrolled.

number0
onIndexChange

Called with the new index when the current slide changes (buttons, indicators, swipe, autoplay).

(index: number) => void—
slidesPerView

How many slides fit in view. Fractions show a peek of the next slide (e.g. 1.2). Responsive: { base: 1, md: 2, lg: 3 }.

Responsive<number>1
gap

Space between slides (a --space-* step). Responsive.

Responsive<Space>4
loop

Wraps Previous / Next (and arrow keys) around the ends. When false, the buttons disable at the first and last positions.

booleanfalse
indicators

Shows a row of slide picker buttons ("Go to slide 3") below the slides.

booleanfalse
autoplay

Rotates slides automatically every interval ms and shows a Pause / Play button as the first control. Rotation pauses while hovered, stops when keyboard focus enters the carousel, and doesn't start on its own under prefers-reduced-motion (the Play button still works).

booleanfalse
interval

Time each slide shows during autoplay, in milliseconds.

number5000
controlsPlacement

Where the Previous / Next buttons sit.

"overlay""bottom""overlay"
radius

Corner rounding of each slide.

"none""xs""sm""md""lg""xl""2xl""pill""lg"
labels

Overrides for the built-in control names and announcements.

Partial<CarouselLabels>—
className

Additional class names for the root <section>.

string—
aria-label

Accessible name of the carousel, e.g. "Game highlights". Required unless aria-labelledby is set.

string—
aria-labelledby

Id of a visible heading that names the carousel. Required unless aria-label is set.

string—

Also accepts native <section> attributes, plus className, style and ref.

One slide. See CarouselSlide.

Carousel.Slide props
PropTypeDefault
label

Accessible name of the slide. Defaults to its position, e.g. "3 of 8". Ignored when aria-label or aria-labelledby is passed.

string—
children

The slide content.

ReactNode—

Also accepts native <div> attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

Carousel targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TabMoves through the rotation, Previous and Next buttons, the indicators, and the slides region.
Arrow RightArrow LeftOn the slides region: next or previous slide (mirrored right to left).
HomeEndOn the slides region: first or last slide.
EnterSpaceActivates the focused button or indicator.

Autoplay pauses while the carousel has focus or the pointer is over it. Slides out of view are inert.

Roles and states

Roles and states
ElementRoleStates and properties
<section>regionaria-roledescription="carousel", aria-label
Each slidegrouparia-roledescription="slide", aria-label ("2 of 5")
Previous / Next buttonsbuttonaria-controls → slides
Indicator buttonsbuttonaria-current on the shown slide
Live regionnonearia-live="polite" while autoplay is off

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)