Logo Docs

Carousel

Carousel

Basic usage

Root holds a viewport (scroll container) and slides (data-mv-carousel-item). Add tabIndex={0} (or tabindex="0" in HTML) so ArrowLeft / ArrowRight work when the carousel is focused.

Product roadmap
Product roadmap
Product roadmap

Keyboard

Put tabindex="0" (or tabIndex={0}) on the carousel root so it can receive focus, then use ArrowLeft / ArrowRight to go to the previous or next slide while focus is inside the carousel (including on the root). The handler skips arrow keys when focus is ...

Focus the carousel (click inside it or press Tab), then use ← / → to move between slides. Arrow keys are ignored while typing in inputs.

Slide 1
Slide 2
Slide 3
Slide 4

Scrollbar visible

By default the viewport and thumbnail strip use hidden native scrollbars (scrolling still works). Set data-mv-carousel-show-scrollbar="true" on the root—or pass showScrollbar: true to getOrCreateInstance—to show them. This example also adds mv-scrollab...

First slide
Second slide
Third slide

Overlay arrows

Add prev/next buttons as overlay controls inside a relative carousel wrapper so they stay visible and easy to click.

First slide
Second slide
Third slide

Autoplay

Autoplay respects prefers-reduced-motion: reduce (timer is not started). Hover and focus-in pause autoplay when data-mv-carousel-pause-on-hover is true (default).

Auto 1
Auto 2
Auto 3

Infinite loop

At the last slide, Next wraps to the first; at the first, Previous wraps to the last.

Loop A
Loop B
Loop C

RTL

Set dir="rtl" on the root (or rely on document direction). Arrow keys follow visual next / previous in RTL.

يمين
وسط
يسار

Multiple slides

Use CSS (min-w-[45%], etc.) so several slides peek into the viewport; the component still advances one slide index per next/prev.

One
Two
Three
Four
Five
Six

Centered

data-mv-carousel-centered="true" scrolls the active slide with inline: "center".

A
B
C
D
E
F

Draggable

Pointer-drag on the viewport scrolls horizontally. Not combined with snap in this API: when data-mv-carousel-snap="true", draggable behavior is disabled.

Drag horizontally on the track (snap is off).

Drag 1
Drag 2
Drag 3
Drag 4
Drag 5
Drag 6

Auto height

data-mv-carousel-auto-height="true" sets the viewport height from the active slide (see ResizeObserver in implementation).

Short slide
Taller slide
Medium slide

Snap

Add Tailwind snap-x / snap-mandatory on the viewport and snap-center on items; enable data-mv-carousel-snap="true" so drag is not attached.

Viewport uses scroll snap; draggable is disabled when snap is on.

Snap 1
Snap 2
Snap 3
Snap 4
Snap 5
Snap 6

Info

data-mv-carousel-current and data-mv-carousel-total show 1-based current index and slide count.

Alpha
Beta
Gamma
0 / 0

Thumbnails (horizontal)

data-mv-carousel-thumbnails wraps controls; each data-mv-carousel-thumbnail maps to a slide by DOM order.

T1
T2
T3
T4
T5
T6

Thumbnails (vertical)

Same behavior with a column layout.

V1
V2
V3
V4
V5
V6

Destroy & reinitialize

Use MVCarousel.getInstance(root)?.dispose() then MVCarousel.getOrCreateInstance(root) after dynamic updates.