Skip to content

Carousel

Slides you can swipe through, with previous and next buttons, dots and arrow keys. Same markup and props in every style: switch the style in the header to see it change.

Basic

One slide at a time. Swipe, scroll with a trackpad, use the buttons or dots, or focus it and press the arrow keys. In HTML, add data-vin-carousel and include vinui.js.

Several per view

Three cards at a time (fewer on small screens), no dots.

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add carousel
React
import { Carousel } from "@/components/vin/carousel";
Vue
import Carousel from "@/components/vin/carousel.vue";
Svelte
import Carousel from "$lib/components/vin/carousel.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/carousel.json, which every framework version is tested against.

PropValuesDefaultIn HTML
label
Names the carousel, e.g. "Featured stays". Required.
string—aria-label on section.vin-carousel[aria-roledescription=carousel]
children
One child per slide. Each is wrapped in a slide labelled "1 of 4".
ReactNode[]—div.vin-carousel__slide[role=group][aria-roledescription=slide][aria-label="1 of 4"] inside .vin-carousel__track
perView
How many slides show at once. Fractions show a peek of the next one. On narrow screens it drops to at most 2, then about 1.2.
number1style="--vin-carousel-per-view: 3" on .vin-carousel
dots
A dot for each slide. Turn off for many slides or several per view.
booleantruediv.vin-carousel__dots > button.vin-carousel__dot
controls
Previous and next buttons. Swiping, scrolling and arrow keys work either way.
booleantruebutton.vin-btn.vin-btn--outline.vin-btn--icon.vin-carousel__prev / __next
gap
Space between slides.
string12pxstyle="--vin-carousel-gap: 16px"
onSlideChange
Called with the first fully shown slide (0-based).
(index: number) => void——

Parts

React, Vue, SvelteHTML classes
<Carousel>.vin-carousel.vin-carousel__track.vin-carousel__slide.vin-carousel__controls.vin-carousel__prev.vin-carousel__next.vin-carousel__dots.vin-carousel__dot

Accessibility

  • Follows the WAI-ARIA carousel pattern: a section with aria-roledescription="carousel" and a label, and slides with role="group", aria-roledescription="slide" and a label like "1 of 4".
  • No autoplay, so nothing moves unless the person moves it. The slides are a polite live region, so a screen reader reads the new slide.
  • Slides that are out of view are inert: Tab skips their links and screen readers skip their text.
  • Previous and Next are buttons with names; at the ends they get aria-disabled="true" (not disabled), so focus never gets lost.
  • The dots are buttons named "Slide 1", "Slide 2"…, and the current one has aria-current="true". Each dot's hit area is 24 by 24 pixels.
  • The slide track is a native scroll-snap scroller, so touch swipe and trackpads work without JavaScript. It can be focused, and the arrow keys move one slide.
  • With reduced motion on, slides jump instead of gliding.