Data display
Carousel
Free19.1 KB gzippedA 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
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".
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.
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.
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.
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
| Prop | Type | Default |
|---|---|---|
childrenThe slides: | ReactNode | — |
indexControlled index of the current (leading) slide, 0-based. | number | — |
defaultIndexInitial index when uncontrolled. | number | 0 |
onIndexChangeCalled with the new index when the current slide changes (buttons, indicators, swipe, autoplay). | (index: number) => void | — |
slidesPerViewHow many slides fit in view. Fractions show a peek of the next slide (e.g. | Responsive<number> | 1 |
gapSpace between slides (a | Responsive<Space> | 4 |
loopWraps Previous / Next (and arrow keys) around the ends. When | boolean | false |
indicatorsShows a row of slide picker buttons ("Go to slide 3") below the slides. | boolean | false |
autoplayRotates slides automatically every | boolean | false |
intervalTime each slide shows during autoplay, in milliseconds. | number | 5000 |
controlsPlacementWhere the Previous / Next buttons sit. | "overlay""bottom" | "overlay" |
radiusCorner rounding of each slide. | "none""xs""sm""md""lg""xl""2xl""pill" | "lg" |
labelsOverrides for the built-in control names and announcements. | Partial<CarouselLabels> | — |
classNameAdditional class names for the root | string | — |
aria-labelAccessible name of the carousel, e.g. "Game highlights". Required unless | string | — |
aria-labelledbyId of a visible heading that names the carousel. Required unless | string | — |
Also accepts native <section> attributes, plus className, style and ref.
Carousel.Slide
One slide. See CarouselSlide.
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the slide. Defaults to its position, e.g. "3 of 8". Ignored when | string | — |
childrenThe 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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 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
| Key | Action |
|---|---|
| Tab | Moves through the rotation, Previous and Next buttons, the indicators, and the slides region. |
| Arrow RightArrow Left | On the slides region: next or previous slide (mirrored right to left). |
| HomeEnd | On the slides region: first or last slide. |
| EnterSpace | Activates 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
| Element | Role | States and properties |
|---|---|---|
<section> | region | aria-roledescription="carousel", aria-label |
| Each slide | group | aria-roledescription="slide", aria-label ("2 of 5") |
| Previous / Next buttons | button | aria-controls → slides |
| Indicator buttons | button | aria-current on the shown slide |
| Live region | none | aria-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.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |