---
title: "Carousel"
description: "A set of slides shown one or a few at a time, scrolled with touch, mouse, wheel, keyboard or controls."
canonical_url: "https://vinicunca.dev/akar/components/carousel"
---
# Carousel

> A set of slides shown one or a few at a time, scrolled with touch, mouse, wheel, keyboard or controls.

```vue [AkarDemoCarousel.vue]
<script setup lang="ts">
import { CarouselContent, CarouselIndicator, CarouselIndicatorGroup, CarouselItem, CarouselNext, CarouselPrevious, CarouselRoot, CarouselViewport } from 'akar';
import './styles.css';

const slides = [
  'Mountains',
  'Lakes',
  'Forests',
  'Deserts',
  'Coasts',
];
</script>

<template>
  <div class="akar-demo akar-demo-Carousel">
    <CarouselRoot
      v-slot="{ snapCount }"
      class="CarouselRoot"
      aria-label="Landscapes"
      loop
    >
      <CarouselViewport class="CarouselViewport">
        <CarouselContent>
          <CarouselItem
            v-for="slide in slides"
            :key="slide"
            class="CarouselItem"
          >
            <div class="CarouselSlide">
              {{ slide }}
            </div>
          </CarouselItem>
        </CarouselContent>
      </CarouselViewport>

      <div class="CarouselControls">
        <CarouselPrevious class="CarouselButton">
          <PIcon name="i-lucide-chevron-left" />
        </CarouselPrevious>
        <CarouselIndicatorGroup class="CarouselIndicators">
          <CarouselIndicator
            v-for="(_, index) in snapCount"
            :key="index"
            :index="index"
            class="CarouselIndicator"
          />
        </CarouselIndicatorGroup>
        <CarouselNext class="CarouselButton">
          <PIcon name="i-lucide-chevron-right" />
        </CarouselNext>
      </div>
    </CarouselRoot>
  </div>
</template>
```

```css [styles.css]
@import '../_colors/grass.css';

@scope (.akar-demo-Carousel) {
  /* reset */
  button {
    all: unset;
  }

  .CarouselRoot {
    width: 320px;
  }

  .CarouselViewport {
    border-radius: 8px;
    outline: none;
  }
  .CarouselViewport:focus-visible {
    box-shadow: 0 0 0 2px var(--grass-7);
  }

  .CarouselItem {
    flex-basis: 100%;
  }

  .CarouselSlide {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 160px;
    border-radius: 8px;
    border: 1px solid var(--ui-color-border);
    background-color: var(--ui-color-bg);
    color: var(--ui-color-text-highlighted);
    font-size: 18px;
    font-weight: 500;
  }

  .CarouselControls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
  }

  .CarouselButton {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    border: 1px solid var(--ui-color-border);
    background-color: var(--ui-color-bg);
    color: var(--ui-color-text-highlighted);
    cursor: pointer;
  }
  .CarouselButton:hover {
    background-color: var(--ui-color-bg-elevated);
  }
  .CarouselButton:focus-visible,
  .CarouselIndicator:focus-visible {
    box-shadow: 0 0 0 2px var(--grass-7);
  }
  .CarouselButton[data-disabled] {
    opacity: 0.5;
    cursor: default;
  }

  .CarouselIndicators {
    display: flex;
    gap: 6px;
  }

  .CarouselIndicator {
    width: 8px;
    height: 8px;
    border-radius: 9999px;
    background-color: var(--ui-color-border-accented);
    cursor: pointer;
    transition:
      width 200ms,
      background-color 200ms;
  }
  .CarouselIndicator[data-active] {
    width: 20px;
    background-color: var(--ui-color-primary);
  }
}
```

## Features

- Can be controlled or uncontrolled.
- Built on native scroll snapping: renders and scrolls before hydration.
- Touch, mouse, pen, wheel, trackpad and keyboard navigation.
- Supports horizontal/vertical orientation and RTL.
- Loop, alignment, groups of slides, free dragging and fade.
- Autoplay and continuous auto scroll with a rotation control.
- Follows the WAI-ARIA carousel pattern and respects reduced motion.
- No dependencies.

## Installation

Install the component from your command line.

```bash [pnpm]
pnpm add akar
```

```bash [yarn]
yarn add akar
```

```bash [npm]
npm install akar
```

```bash [bun]
bun add akar
```

## Anatomy

Import all parts and piece them together.

```vue
<script setup>
import {
  CarouselAutoplayToggle,
  CarouselContent,
  CarouselIndicator,
  CarouselIndicatorGroup,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
  CarouselRoot,
  CarouselViewport,
} from 'akar';
</script>

<template>
  <CarouselRoot v-slot="{ snapCount }">
    <CarouselAutoplayToggle />
    <CarouselViewport>
      <CarouselContent>
        <CarouselItem />
      </CarouselContent>
    </CarouselViewport>
    <CarouselPrevious />
    <CarouselNext />
    <CarouselIndicatorGroup>
      <CarouselIndicator
        v-for="(_, index) in snapCount"
        :key="index"
        :index="index"
      />
    </CarouselIndicatorGroup>
  </CarouselRoot>
</template>
```

## How it works

`CarouselViewport` is a real scroll container with CSS scroll snapping, and `CarouselContent` is the track inside it. Before hydration the browser already scrolls it with touch, a trackpad or the keyboard, and snaps to the slides. Once mounted, the carousel measures the track, adds mouse and pen dragging, the controls and the options below, and keeps `v-model` in sync with the scroll position.

A mouse or pen drag follows the pointer, stretches a little past the first and last slides, and settles on a snap based on its speed. A press on a field inside a slide (an input, a textarea, a select or an editable element) is left to the field. `settle` fires once the slides rest on a new snap, which is the moment for heavier work such as loading the next images.

The parts set the layout styles they need inline: the overflow and snapping on the viewport, `display: flex` on the content and `flex-shrink: 0` on the items. Give the items their size yourself, for example `flex-basis: 100%` for one slide per view or `33.333%` for three. To space them, put a start padding on the items and the same negative start margin on the content, for example `ps-4` and `-ms-4`, or `pt-4` and `-mt-4` when vertical. The carousel measures where the first slide rests and rests every snap at that offset, so the gutter lines up on every slide. Before hydration the browser snaps to the item edges, so the slides sit one gutter off until the track is measured.

`v-model` is the index of the current **snap**, not of a slide. With one slide per snap they are the same. With `slidesToScroll`, or when `containScroll` merges the snaps at the end of the track, there are fewer snaps than slides: render the indicators from the `snapCount` slot prop.

### Server rendering

The server renders a working scroller: before hydration, visitors can already swipe, scroll with a trackpad or the keyboard, and land on a snap. The current slide has `data-active`, and with `fade` the other slides are hidden. Where the browser supports `scroll-initial-target`, the track opens on `defaultValue`; elsewhere it scrolls there on hydration. If a visitor scrolls before hydration, the carousel keeps that place and `v-model` follows it.

The slides register once they mount, so on the server `snapCount` is `0`, Previous/Next are disabled and the slides have no "2 of 5" label. Pass `itemCount` with the number of slides to render the indicators, the controls and the labels on the server too. Until the track is measured, every group of `slidesToScroll` slides counts as one snap.

### Wrapping the parts

`CarouselRoot` declares `draggable` and `defaultPlaying` with a `true` default and `playing` with an `undefined` one. A component that wraps it and redeclares these props needs the same defaults in its `withDefaults`, or Vue casts the absent booleans to `false`, which turns dragging and rotation off and makes `playing` controlled.

## API Reference

### Root

Contains all the parts of a carousel. Renders a `region` with `aria-roledescription="carousel"`: give it a name with `aria-label` or `aria-labelledby`.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `align` | `"start"` | `"start" \| "center" \| "end"` | Where a snap places its slides in the viewport. |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |
| `autoHeight` |  | `boolean` | When `true`, the viewport takes the height of the current slides. Horizontal only. |
| `autoplay` | `false` | `boolean \| CarouselAutoplayOptions` | Advance to the next snap on an interval. Pauses on hover, stops when keyboard focus enters the carousel. |
| `autoScroll` | `false` | `boolean \| CarouselAutoScrollOptions` | Scroll the track continuously. Pauses on hover, stops when keyboard focus enters the carousel. |
| `containScroll` | `"trimSnaps"` | `false \| "trimSnaps" \| "keepSnaps"` | How the snaps at the ends of the track are handled. `'trimSnaps'` merges the snaps that would leave empty space,<br>`'keepSnaps'` keeps one snap per group, `false` adds empty space so every snap can be aligned. Ignored with `loop`. |
| `defaultPlaying` | `true` | `boolean` | The rotation state when initially rendered. Rotation stops on mount when the user prefers reduced motion. |
| `defaultValue` | `0` | `number` | The index of the snap to show when initially rendered. Use when you do not need to control the index. |
| `dir` |  | `"ltr" \| "rtl"` | The reading direction of the carousel.<br><br>If omitted, inherits globally from `ConfigProvider` or assumes LTR (left-to-right) reading mode. |
| `dragFree` |  | `boolean` | When `true`, the track scrolls freely with momentum instead of resting on a snap. |
| `draggable` | `true` | `boolean` | When `false`, the track can't be dragged, swiped or scrolled by the user; the controls still navigate. |
| `fade` |  | `boolean` | When `true`, slides are stacked and cross-fade instead of sliding. Set the `transition` on the items yourself. |
| `inViewThreshold` | `0` | `number` | The fraction (0 to 1) of an item that has to be visible for it to count as in view. |
| `itemCount` |  | `number` | The number of slides. Only needed on the server, to render `snapCount`, the indicators, the enabled<br>Previous/Next and the slide labels before hydration: the slides register once mounted, and their count wins from then on. |
| `loop` |  | `boolean` | When `true`, the last slide is followed by the first one, and vice versa. When the slides are too few to wrap, Next on the last snap scrolls back to the first instead. |
| `modelValue` |  | `number` | The controlled index of the current snap. Can be bound as `v-model`. |
| `orientation` | `"horizontal"` | `"vertical" \| "horizontal"` | The axis the slides are laid out and scroll along. |
| `playing` |  | `boolean` | The controlled rotation state of `autoplay` or `autoScroll`. Can be bound as `v-model:playing`. |
| `skipSnaps` |  | `boolean` | When `true`, a fast gesture can move past several snaps. When `false`, one gesture moves one snap. |
| `slidesToScroll` | `1` | `number \| "auto"` | How many slides one navigation step moves. `'auto'` moves as many as fit in the viewport. |
| `wheel` |  | `boolean` | When `true`, a mouse wheel pages through the snaps, and in `fade` mode the wheel and trackpad do too. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `settle` | `value: number` | Event handler called once the slides rest on the current snap after a change: after the scroll, drag or fade that moved them. |
| `update:modelValue` | `value: number` | Event handler called when the current snap changes. |
| `update:playing` | `value: boolean` | Event handler called when rotation starts or stops. |

**Slots**

| Slot | Payload | Description |
| --- | --- | --- |
| `modelValue` | `number` | The current snap index |
| `snapCount` | `number` | The number of snaps |
| `canScrollPrev` | `boolean` | Whether there is a snap before the current one |
| `canScrollNext` | `boolean` | Whether there is a snap after the current one |
| `scrollPrev` | `(): boolean` | Go to the previous snap |
| `scrollNext` | `(): boolean` | Go to the next snap |
| `scrollTo` | `(index: number): boolean` | Go to the snap at `index` |
| `playing` | `boolean` | Whether `autoplay` or `autoScroll` is rotating |
| `paused` | `boolean` | Whether rotation is held for now: hover, a hidden page, the carousel out of view, a finger down |
| `play` | `(): boolean` | Start rotation |
| `stop` | `(): boolean` | Stop rotation |

[CarouselRoot.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselRoot.vue)

| Data attribute | Value |
| --- | --- |
| `[data-orientation]` | "vertical" \\| "horizontal" |
| `[data-playing]` | Present while autoplay or auto scroll is on |
| `[data-paused]` | Present while rotation is held: hovered, a hidden page, scrolled out of view, or a finger down |

| CSS variable | Description |
| --- | --- |
| `--akar-carousel-progress` | From 0 at the first snap to 1 at the last, updated on every scroll frame. With `loop` it wraps back to 0 |
| `--akar-carousel-interval` | The `autoplay` delay, to time a progress animation |

### Viewport

The scroll container. It is focusable and handles the arrow keys, `Home` and `End`.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[CarouselViewport.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselViewport.vue)

| Data attribute | Value |
| --- | --- |
| `[data-orientation]` | "vertical" \\| "horizontal" |
| `[data-dragging]` | Present while the track is dragged with a mouse or pen |

| CSS variable | Description |
| --- | --- |
| `--akar-carousel-height` | The height of the current slides, with `autoHeight` |

### Content

The track that holds the slides. It is a polite live region, turned off while the carousel rotates on its own.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[CarouselContent.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselContent.vue)

| Data attribute | Value |
| --- | --- |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### Item

A slide. Renders a `group` with `aria-roledescription="slide"`, or a `tabpanel` next to a `CarouselIndicatorGroup`, labelled with its position ("2 of 5") unless you pass `aria-label` or `aria-labelledby`. It gets a generated `id` for the tabs to point at. Once measured, slides out of view are `inert` and hidden from assistive technologies.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

**Slots**

| Slot | Payload | Description |
| --- | --- | --- |
| `active` | `boolean` | Whether the current snap brings this item into place |
| `inView` | `boolean` | Whether the item is visible in the viewport |

[CarouselItem.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselItem.vue)

| Data attribute | Value |
| --- | --- |
| `[data-index]` | The slide index |
| `[data-active]` | Present when the current snap brings the slide into place |
| `[data-in-view]` | Present when the slide is visible in the viewport |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### Previous

Goes to the previous snap. On the first one, unless `loop` is set, it is `aria-disabled` and does nothing, but keeps the focus.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"button"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[CarouselPrevious.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselPrevious.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when there is no previous snap |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### Next

Goes to the next snap. On the last one, unless `loop` is set, it is `aria-disabled` and does nothing, but keeps the focus.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"button"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[CarouselNext.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselNext.vue)

| Data attribute | Value |
| --- | --- |
| `[data-disabled]` | Present when there is no next snap |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### IndicatorGroup

Wraps the indicators in a `tablist`, labelled "Choose slide to display" unless you pass `aria-label`. Its indicators become tabs: the current one is the only tab stop, and the arrow keys, `Home` and `End` move between them and show their snap. The slides become the tab panels, following the tabbed carousel pattern: each tab is labelled "Slide 1", "Slide 2"..., its `aria-controls` points at the slides of its snap, and those slides are labelled by it through `aria-labelledby`. To translate, label the tabs. With two groups, for example dots and thumbnails, each keeps its own tab ids and the slides are labelled by the first one. The slides switch once the group mounts, so the server renders them as slide groups.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"div"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

[CarouselIndicatorGroup.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselIndicatorGroup.vue)

| Data attribute | Value |
| --- | --- |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### Indicator

Goes to the snap at `index`. In a `CarouselIndicatorGroup` it is a `tab` with `aria-selected`. On its own it is a button, and the current one has `aria-disabled="true"`.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"button"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |
| `index*` |  | `number` | The index of the snap this indicator goes to. |

**Slots**

| Slot | Payload | Description |
| --- | --- | --- |
| `active` | `boolean` | Whether this indicator's snap is the current one |

[CarouselIndicator.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselIndicator.vue)

| Data attribute | Value |
| --- | --- |
| `[data-active]` | Present when its snap is the current one |
| `[data-orientation]` | "vertical" \\| "horizontal" |

### AutoplayToggle

Starts and stops `autoplay` or `autoScroll`. Its label names the action it takes next ("Stop slide rotation", "Start slide rotation"). Place it first in the carousel, so it is the first thing keyboard users reach.

**Props**

| Prop | Default | Type | Description |
| --- | --- | --- | --- |
| `as` | `"button"` | `AsTag \| Component` | The element or component this component should render as. Can be overwritten by `asChild`. |
| `asChild` |  | `boolean` | Change the default rendered element for the one passed as a child, merging their props and behavior.<br><br>Read our [Composition](https://vinicunca.dev/akar/guides/composition) guide for more details. |

**Slots**

| Slot | Payload | Description |
| --- | --- | --- |
| `playing` | `boolean` | Whether `autoplay` or `autoScroll` is rotating |

[CarouselAutoplayToggle.vue source](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel/CarouselAutoplayToggle.vue)

| Data attribute | Value |
| --- | --- |
| `[data-state]` | "playing" \\| "paused" |
| `[data-disabled]` | Present when neither autoplay nor autoScroll is set |

## Examples

### Several slides per view

Size the items to fit several in the viewport. `align` places the current snap, and `slidesToScroll` moves several slides per step, or as many as fit with `'auto'`.

```vue {4,5}
<template>
  <CarouselRoot
    aria-label="Products"
    align="start"
    slides-to-scroll="auto"
  >
    <CarouselViewport>
      <CarouselContent class="-ml-4">
        <CarouselItem
          v-for="product in products"
          :key="product.id"
          class="basis-1/3 pl-4"
        >
          ...
        </CarouselItem>
      </CarouselContent>
    </CarouselViewport>
  </CarouselRoot>
</template>
```

### Controlling the current slide

Bind `v-model` to read or set the current snap.

```vue {4,9}
<script setup lang="ts">
import { ref } from 'vue'

const current = ref(0)
</script>

<template>
  <CarouselRoot
    v-model="current"
    aria-label="Gallery"
  >
    ...
  </CarouselRoot>
  <p>Slide {{ current + 1 }}</p>
</template>
```

### Thumbnails

Two carousels can share the same `v-model`: the thumbnails follow the main one, and selecting a thumbnail moves it. `containScroll: 'keepSnaps'` keeps one snap per thumbnail, so both carousels count the same snaps.

```vue
<template>
  <CarouselRoot
    v-model="current"
    aria-label="Photos"
  >
    ...
  </CarouselRoot>
  <CarouselRoot
    v-model="current"
    aria-label="Thumbnails"
    align="center"
    contain-scroll="keepSnaps"
  >
    <CarouselViewport>
      <CarouselContent>
        <CarouselItem
          v-for="(photo, index) in photos"
          :key="photo.id"
          class="basis-1/4"
        >
          <button
            :aria-current="index === current"
            @click="current = index"
          >
            <img
              :src="photo.thumbnail"
              :alt="photo.alt"
            >
          </button>
        </CarouselItem>
      </CarouselContent>
    </CarouselViewport>
  </CarouselRoot>
</template>
```

### Autoplay

`autoplay` moves to the next snap on an interval, and `autoScroll` scrolls the track continuously. Both pause while a mouse hovers the carousel, while the page is hidden, while the carousel is scrolled out of view and while a finger is down on it. They stop when keyboard focus enters it, and stop on mount when the user prefers reduced motion. With `stopOnInteraction`, the default, they also stop on the first drag, press or key. Bind `v-model:playing` to control them.

```vue {3,5}
<template>
  <CarouselRoot
    :autoplay="{ delay: 5000 }"
    aria-label="Announcements"
    loop
  >
    <CarouselAutoplayToggle v-slot="{ playing }">
      {{ playing ? 'Pause' : 'Play' }}
    </CarouselAutoplayToggle>
    ...
  </CarouselRoot>
</template>
```

### Fade

With `fade`, the slides are stacked and the current one has `opacity: 1`, the others `opacity: 0`. Add the transition to the items.

```vue {3,9}
<template>
  <CarouselRoot
    fade
    aria-label="Testimonials"
  >
    <CarouselViewport>
      <CarouselContent>
        <CarouselItem class="transition-opacity duration-500">
          ...
        </CarouselItem>
      </CarouselContent>
    </CarouselViewport>
  </CarouselRoot>
</template>
```

### Auto height

With `autoHeight`, the viewport takes the height of the current slides. Animate it with a `height` transition on the viewport.

```vue {3,6}
<template>
  <CarouselRoot
    auto-height
    aria-label="Reviews"
  >
    <CarouselViewport class="transition-[height] duration-300">
      ...
    </CarouselViewport>
  </CarouselRoot>
</template>
```

### Styling slides by state

`data-active` marks the slides of the current snap and `data-in-view` the visible ones, for example to dim the slides around a centered one.

```vue {5}
<template>
  <CarouselItem
    v-for="slide in slides"
    :key="slide.id"
    class="opacity-40 transition-opacity data-[active]:opacity-100"
  >
    {{ slide.title }}
  </CarouselItem>
</template>
```

## Accessibility

Adheres to the [Carousel WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/carousel).

The root is a `region` with `aria-roledescription="carousel"`, each item a `group` with `aria-roledescription="slide"`, and the content a live region that announces slide changes, except while the carousel rotates on its own. The controls point at the content with `aria-controls`. Slides out of view are `inert`, so keyboard and screen reader users only meet the visible ones. When the slide holding the focus leaves the view, the focus moves to the slide that comes in, or to the viewport when it has nothing to focus. Previous and Next stay focusable at the ends, and `CarouselIndicatorGroup` turns the indicators into a tablist with a single tab stop.

Rotation follows the pattern: it pauses on hover, stops for good when keyboard focus enters the carousel, and only restarts from `CarouselAutoplayToggle`. When the user prefers reduced motion, rotation stops on mount and programmatic scrolls jump instead of animating.

### Keyboard Interactions

| Key | Description |
| --- | --- |
| <kbd>Tab</kbd> | Moves focus through the controls, the viewport and the visible slides. |
| <kbd>ArrowRight</kbd> | When the viewport is focused, goes to the next snap in a horizontal carousel. |
| <kbd>ArrowLeft</kbd> | When the viewport is focused, goes to the previous snap in a horizontal carousel. |
| <kbd>ArrowDown</kbd> | When the viewport is focused, goes to the next snap in a vertical carousel. |
| <kbd>ArrowUp</kbd> | When the viewport is focused, goes to the previous snap in a vertical carousel. |
| <kbd>Home</kbd> | When the viewport is focused, goes to the first snap. |
| <kbd>End</kbd> | When the viewport is focused, goes to the last snap. |
| <kbd>ArrowRight</kbd> / <kbd>ArrowLeft</kbd> | In a `CarouselIndicatorGroup`, moves to the next or previous indicator and shows its snap. |
| <kbd>Space</kbd> / <kbd>Enter</kbd> | Activates the focused control. |

### Labels

The built-in accessible labels are in English. Override them with attributes: `aria-roledescription` on `CarouselRoot` and `CarouselItem`, and `aria-label` on `CarouselItem`, `CarouselPrevious`, `CarouselNext`, `CarouselIndicator`, `CarouselIndicatorGroup` and `CarouselAutoplayToggle`, whose label follows the `playing` slot prop of the root. The item label is its position, built from the `v-for` index and the number of slides. Next to a `CarouselIndicatorGroup` the slides take their name from the tabs, so label the indicators instead.

```vue
<template>
  <CarouselRoot
    v-slot="{ playing }"
    :aria-label="t('carousel.label')"
    :aria-roledescription="t('carousel.roledescription')"
  >
    <CarouselAutoplayToggle :aria-label="playing ? t('carousel.stop') : t('carousel.start')" />
    <CarouselViewport>
      <CarouselContent>
        <CarouselItem
          v-for="(slide, index) in slides"
          :key="slide.id"
          :aria-roledescription="t('carousel.slide')"
          :aria-label="t('carousel.position', { index: index + 1, total: slides.length })"
        >
          ...
        </CarouselItem>
      </CarouselContent>
    </CarouselViewport>
    <CarouselPrevious :aria-label="t('carousel.previous')" />
    <CarouselNext :aria-label="t('carousel.next')" />
  </CarouselRoot>
</template>
```

In a right-to-left layout (`dir="rtl"` on `CarouselRoot`, or on a [`ConfigProvider`](https://vinicunca.dev/akar/utilities/config-provider)), `ArrowLeft` goes to the next snap and `ArrowRight` to the previous one. See [Internationalization](https://vinicunca.dev/akar/guides/i18n#rtl).

---

- [ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/carousel)
- [GitHub](https://github.com/vinicunca/akar/blob/v2.3.0/packages/core/src/Carousel)
- [npm](https://www.npmjs.com/package/akar)


## Sitemap

See the full [sitemap](https://vinicunca.dev/sitemap.md) for all pages.
