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.
<section class="vin-carousel" aria-roledescription="carousel" aria-label="Getting started" data-vin-carousel style="max-width: 520px">
<div class="vin-carousel__track" id="tour-slides" tabindex="0" aria-live="polite">
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="1 of 4">
<div style="display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)">
<h3 class="vin-h3" style="margin: 0">Pick a style</h3>
<p class="vin-p" style="margin: 0">Eight looks, one set of components.</p>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="2 of 4">
<div style="display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)">
<h3 class="vin-h3" style="margin: 0">Choose an accent</h3>
<p class="vin-p" style="margin: 0">Any colour. Text on it stays readable.</p>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="3 of 4">
<div style="display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)">
<h3 class="vin-h3" style="margin: 0">Copy the code</h3>
<p class="vin-p" style="margin: 0">Plain HTML or React. No build step needed.</p>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="4 of 4">
<div style="display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)">
<h3 class="vin-h3" style="margin: 0">Ship it</h3>
<p class="vin-p" style="margin: 0">Light, dark and accessible out of the box.</p>
</div>
</div>
</div>
<div class="vin-carousel__controls">
<button type="button" class="vin-btn vin-btn--outline vin-btn--icon vin-carousel__prev" aria-controls="tour-slides" aria-label="Previous slide" aria-disabled="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg></button>
<div class="vin-carousel__dots" role="group" aria-label="Choose a slide">
<button type="button" class="vin-carousel__dot" aria-controls="tour-slides" aria-label="Slide 1" aria-current="true"></button>
<button type="button" class="vin-carousel__dot" aria-controls="tour-slides" aria-label="Slide 2"></button>
<button type="button" class="vin-carousel__dot" aria-controls="tour-slides" aria-label="Slide 3"></button>
<button type="button" class="vin-carousel__dot" aria-controls="tour-slides" aria-label="Slide 4"></button>
</div>
<button type="button" class="vin-btn vin-btn--outline vin-btn--icon vin-carousel__next" aria-controls="tour-slides" aria-label="Next slide"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></button>
</div>
</section>import { Carousel } from "@/components/vin/carousel";
import { Heading, Text } from "@/components/vin/typography";
const steps = [
["Pick a style", "Eight looks, one set of components."],
["Choose an accent", "Any colour. Text on it stays readable."],
["Copy the code", "Plain HTML or React. No build step needed."],
["Ship it", "Light, dark and accessible out of the box."],
];
const panel = {
display: "grid", alignContent: "end", gap: 6, minHeight: 200, padding: 28,
borderRadius: "var(--vin-radius-lg)", background: "color-mix(in srgb, var(--vin-accent) 13%, transparent)",
} as const;
export function CarouselBasic() {
return (
<Carousel label="Getting started" style={{ maxWidth: 520 }}>
{steps.map(([title, text]) => (
<div key={title} style={panel}>
<Heading level={3} style={{ margin: 0 }}>{title}</Heading>
<Text style={{ margin: 0 }}>{text}</Text>
</div>
))}
</Carousel>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Carousel from "@/components/vin/carousel.vue";
import Heading, { Text } from "@/components/vin/typography.vue";
const steps = [
["Pick a style", "Eight looks, one set of components."],
["Choose an accent", "Any colour. Text on it stays readable."],
["Copy the code", "Plain HTML or React. No build step needed."],
["Ship it", "Light, dark and accessible out of the box."],
];
const panel = "display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)";
</script>
<template>
<Carousel label="Getting started" style="max-width: 520px">
<div v-for="[title, text] in steps" :key="title" :style="panel">
<Heading :level="3" style="margin: 0">{{ title }}</Heading>
<Text style="margin: 0">{{ text }}</Text>
</div>
</Carousel>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Carousel from "$lib/components/vin/carousel.svelte";
import Heading from "$lib/components/vin/typography-heading.svelte";
import Text from "$lib/components/vin/typography.svelte";
const steps = [
["Pick a style", "Eight looks, one set of components."],
["Choose an accent", "Any colour. Text on it stays readable."],
["Copy the code", "Plain HTML or React. No build step needed."],
["Ship it", "Light, dark and accessible out of the box."],
];
const panel =
"display: grid; align-content: end; gap: 6px; min-height: 200px; padding: 28px; border-radius: var(--vin-radius-lg); background: color-mix(in srgb, var(--vin-accent) 13%, transparent)";
</script>
<Carousel label="Getting started" items={steps} style="max-width: 520px">
{#snippet children([title, text])}
<div style={panel}>
<Heading level={3} style="margin: 0">{title}</Heading>
<Text style="margin: 0">{text}</Text>
</div>
{/snippet}
</Carousel>Several per view
Three cards at a time (fewer on small screens), no dots.
<section class="vin-carousel" aria-roledescription="carousel" aria-label="The eight styles" data-vin-carousel style="--vin-carousel-per-view: 3">
<div class="vin-carousel__track" id="style-slides" tabindex="0" aria-live="polite">
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="1 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Precision</h3>
<p class="vin-card__desc">Crisp hairlines, quiet depth.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="2 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Tactile</h3>
<p class="vin-card__desc">Physical, pressable buttons.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="3 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Clay</h3>
<p class="vin-card__desc">Puffy, friendly, inflated.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="4 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Tonal</h3>
<p class="vin-card__desc">Colour-led, pill shapes, springy.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="5 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Editorial</h3>
<p class="vin-card__desc">Typographic, airy, magazine.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="6 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Terminal</h3>
<p class="vin-card__desc">Developer-native, monospace.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="7 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Paper</h3>
<p class="vin-card__desc">Warm, hand-made, human.</p>
</div>
</div>
</div>
<div class="vin-carousel__slide" role="group" aria-roledescription="slide" aria-label="8 of 8">
<div class="vin-card">
<div class="vin-card__header">
<h3 class="vin-card__title">Bento</h3>
<p class="vin-card__desc">Calm, layered, borderless.</p>
</div>
</div>
</div>
</div>
<div class="vin-carousel__controls">
<button type="button" class="vin-btn vin-btn--outline vin-btn--icon vin-carousel__prev" aria-controls="style-slides" aria-label="Previous slide" aria-disabled="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6"/></svg></button>
<button type="button" class="vin-btn vin-btn--outline vin-btn--icon vin-carousel__next" aria-controls="style-slides" aria-label="Next slide"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6"/></svg></button>
</div>
</section>import { Carousel } from "@/components/vin/carousel";
import { Card, CardHeader, CardTitle, CardDescription } from "@/components/vin/card";
const styles = [
["Precision", "Crisp hairlines, quiet depth."],
["Tactile", "Physical, pressable buttons."],
["Clay", "Puffy, friendly, inflated."],
["Tonal", "Colour-led, pill shapes, springy."],
["Editorial", "Typographic, airy, magazine."],
["Terminal", "Developer-native, monospace."],
["Paper", "Warm, hand-made, human."],
["Bento", "Calm, layered, borderless."],
];
export function CarouselMultiple() {
return (
<Carousel label="The eight styles" perView={3} dots={false}>
{styles.map(([name, text]) => (
<Card key={name}>
<CardHeader>
<CardTitle>{name}</CardTitle>
<CardDescription>{text}</CardDescription>
</CardHeader>
</Card>
))}
</Carousel>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Carousel from "@/components/vin/carousel.vue";
import Card, { CardHeader, CardTitle, CardDescription } from "@/components/vin/card.vue";
const styles = [
["Precision", "Crisp hairlines, quiet depth."],
["Tactile", "Physical, pressable buttons."],
["Clay", "Puffy, friendly, inflated."],
["Tonal", "Colour-led, pill shapes, springy."],
["Editorial", "Typographic, airy, magazine."],
["Terminal", "Developer-native, monospace."],
["Paper", "Warm, hand-made, human."],
["Bento", "Calm, layered, borderless."],
];
</script>
<template>
<Carousel label="The eight styles" :per-view="3" :dots="false">
<Card v-for="[name, text] in styles" :key="name">
<CardHeader>
<CardTitle>{{ name }}</CardTitle>
<CardDescription>{{ text }}</CardDescription>
</CardHeader>
</Card>
</Carousel>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Carousel from "$lib/components/vin/carousel.svelte";
import Card from "$lib/components/vin/card.svelte";
import CardHeader from "$lib/components/vin/card-header.svelte";
import CardTitle from "$lib/components/vin/card-title.svelte";
import CardDescription from "$lib/components/vin/card-description.svelte";
const styles = [
["Precision", "Crisp hairlines, quiet depth."],
["Tactile", "Physical, pressable buttons."],
["Clay", "Puffy, friendly, inflated."],
["Tonal", "Colour-led, pill shapes, springy."],
["Editorial", "Typographic, airy, magazine."],
["Terminal", "Developer-native, monospace."],
["Paper", "Warm, hand-made, human."],
["Bento", "Calm, layered, borderless."],
];
</script>
<Carousel label="The eight styles" items={styles} perView={3} dots={false}>
{#snippet children([name, text])}
<Card>
<CardHeader>
<CardTitle>{name}</CardTitle>
<CardDescription>{text}</CardDescription>
</CardHeader>
</Card>
{/snippet}
</Carousel>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:
npx @vinish/ui add carouselimport { Carousel } from "@/components/vin/carousel";import Carousel from "@/components/vin/carousel.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
labelNames the carousel, e.g. "Featured stays". Required. | string | — | aria-label on section.vin-carousel[aria-roledescription=carousel] |
childrenOne 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 |
perViewHow 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. | number | 1 | style="--vin-carousel-per-view: 3" on .vin-carousel |
dotsA dot for each slide. Turn off for many slides or several per view. | boolean | true | div.vin-carousel__dots > button.vin-carousel__dot |
controlsPrevious and next buttons. Swiping, scrolling and arrow keys work either way. | boolean | true | button.vin-btn.vin-btn--outline.vin-btn--icon.vin-carousel__prev / __next |
gapSpace between slides. | string | 12px | style="--vin-carousel-gap: 16px" |
onSlideChangeCalled with the first fully shown slide (0-based). | (index: number) => void | — | — |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.