Carousel
VCarousel displays slides in a scrollable track with optional controls, indicators and autoplay.
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { VCarousel, VCarouselItem } from 'vectis-ui'
const slide = ref(0)
</script>
<template>
<VCarousel v-model="slide" label="Gallery">
<VCarouselItem><p class="slide">First slide</p></VCarouselItem>
<VCarouselItem><p class="slide">Second slide</p></VCarouselItem>
<VCarouselItem><p class="slide">Third slide</p></VCarouselItem>
</VCarousel>
</template>
<style scoped>
.slide {
display: grid;
place-items: center;
block-size: 12rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
background: var(--vectis-color-surface-muted);
}
</style>Examples
Items per view
itemsPerView sets the maximum visible slides. itemMinSize reduces that number when the container narrows.
<script setup lang="ts">
import { VCarousel, VCarouselItem } from 'vectis-ui'
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<VCarousel label="Three at a time" :items-per-view="3" :item-min-size="180">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</template>
<style scoped>
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Peek
peek leaves part of the next slide visible, including the gap.
<script setup lang="ts">
import { VCarousel, VCarouselItem } from 'vectis-ui'
const products = ['Kettle', 'Toaster', 'Blender', 'Grinder', 'Scale', 'Press']
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<VCarousel label="Product list" :items-per-view="2" peek="3rem">
<VCarouselItem v-for="(product, i) in products" :key="product">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hues[i]})` }">{{ product }}</p>
</VCarouselItem>
</VCarousel>
</template>
<style scoped>
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Effects
Choose slide, fade or scale. Fade requires one slide per view and no peek; otherwise it falls back to slide.
<script setup lang="ts">
import { VCarousel, VCarouselItem, VTypography, type CarouselEffect } from 'vectis-ui'
const effects: CarouselEffect[] = ['slide', 'fade', 'scale']
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div v-for="effect in effects" :key="effect" class="group">
<VTypography variant="overline" tone="muted">{{ effect }}</VTypography>
<VCarousel :effect="effect" :label="`The ${effect} effect`">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-2);
}
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Orientation
Vertical carousels require an explicit height.
<script setup lang="ts">
import { VCarousel, VCarouselItem, VTypography } from 'vectis-ui'
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div class="group">
<VTypography variant="overline" tone="muted">horizontal</VTypography>
<VCarousel label="Horizontal gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
<div class="group">
<VTypography variant="overline" tone="muted">vertical</VTypography>
<VCarousel orientation="vertical" height="14rem" label="Vertical gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide fill" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-2);
}
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
/* Let content fill the carousel's assigned slide height. */
.fill {
block-size: 100%;
}
</style>Custom icons
Customize controls with prevIcon, nextIcon and their accessible labels.
<script setup lang="ts">
import { VCarousel, VCarouselItem, VTypography } from 'vectis-ui'
import {
chevron_left as chevronLeft,
chevron_right as chevronRight,
expand_less as expandLess,
expand_more as expandMore,
} from 'vectis-ui/icons'
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div class="group">
<VTypography variant="overline" tone="muted">chevrons</VTypography>
<VCarousel label="Chevron controls" :prev-icon="chevronLeft" :next-icon="chevronRight">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
<div class="group">
<VTypography variant="overline" tone="muted">carets</VTypography>
<VCarousel
orientation="vertical"
height="14rem"
label="Caret controls"
:prev-icon="expandLess"
:next-icon="expandMore"
>
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide fill" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-2);
}
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
.fill {
block-size: 100%;
}
</style>Placements
controls and indicators independently accept inside, outside or false.
arrows inside, dots outside arrows inside, dots inside arrows outside, dots outside arrows outside, dots inside <script setup lang="ts">
import {
VCarousel,
VCarouselItem,
VTypography,
type CarouselControls,
type CarouselIndicators,
} from 'vectis-ui'
const placements: {
caption: string
controls: CarouselControls
indicators: CarouselIndicators
}[] = [
{ caption: 'arrows inside, dots outside', controls: 'inside', indicators: 'outside' },
{ caption: 'arrows inside, dots inside', controls: 'inside', indicators: 'inside' },
{ caption: 'arrows outside, dots outside', controls: 'outside', indicators: 'outside' },
{ caption: 'arrows outside, dots inside', controls: 'outside', indicators: 'inside' },
]
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div v-for="placement in placements" :key="placement.caption" class="group">
<VTypography variant="overline" tone="muted">{{ placement.caption }}</VTypography>
<VCarousel
:controls="placement.controls"
:indicators="placement.indicators"
:label="placement.caption"
>
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-2);
}
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Jumps
Multi-page moves jump directly by default. noJump scrolls through the intervening slides.
straight there, the default <script setup lang="ts">
import { VCarousel, VCarouselItem, VTypography } from 'vectis-ui'
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div class="group">
<VTypography variant="overline" tone="muted">straight there, the default</VTypography>
<VCarousel effect="fade" label="Jumping gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
<div class="group">
<VTypography variant="overline" tone="muted">the whole travel</VTypography>
<VCarousel effect="fade" no-jump label="Travelling gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-2);
}
.slide {
display: grid;
place-items: center;
block-size: 10rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Loop
loop wraps navigation from the last position to the first and back.
<script setup lang="ts">
import { VCarousel, VCarouselItem } from 'vectis-ui'
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<VCarousel loop label="Looping gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</template>
<style scoped>
.slide {
display: grid;
place-items: center;
block-size: 12rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>Autoplay
autoplay sets an interval in milliseconds. Hover and focus pause it; reduced motion disables it. Add a pause button by setting the interval to 0.
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, VCarousel, VCarouselItem } from 'vectis-ui'
/* Provide a pause control for users who cannot hover or focus the carousel. */
const paused = ref(false)
const hues = [220, 280, 340, 20, 90, 160]
</script>
<template>
<div class="group">
<VButton variant="outline" tone="neutral" size="sm" class="stop" @click="paused = !paused">
{{ paused ? 'Resume' : 'Pause' }}
</VButton>
<VCarousel :autoplay="paused ? 0 : 3000" label="Rotating gallery">
<VCarouselItem v-for="(hue, i) in hues" :key="hue">
<p class="slide" :style="{ background: `oklch(0.45 0.15 ${hue})` }">{{ i + 1 }}</p>
</VCarouselItem>
</VCarousel>
</div>
</template>
<style scoped>
.group {
display: grid;
gap: var(--vectis-space-3);
}
.stop {
justify-self: start;
}
.slide {
display: grid;
place-items: center;
block-size: 12rem;
margin: 0;
border-radius: var(--vectis-radius-surface);
color: var(--vectis-color-text-on-accent);
font-size: var(--vectis-text-heading-3-size);
font-weight: var(--vectis-text-heading-3-weight);
}
</style>API
Props
Slots
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export interface CarouselControlsSlotProps {
previous: () => void
next: () => void
atStart: boolean
atEnd: boolean
index: number
count: number
pageCount: number
orientation: CarouselOrientation
}export interface CarouselIndicatorSlotProps {
index: number
active: boolean
}export type CarouselOrientation = 'horizontal' | 'vertical'
export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
CSS variables