Carousel
Slides in a scroll-snap viewport: native swipe and scrolling, previous/next controls, indicators, keyboard, loop and autoplay with a pause button.
API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-carousel> · RayCarousel
Any child is a slide. With several slides in view, positions are the snap points the viewport can reach. ArrowLeft/Right (Up/Down when vertical), Home and End move it.
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
index | index | number | 0 | Current position (0-based). Setting it scrolls there. |
label | label | string | Carousel (text carousel.label) | Accessible name of the carousel region. |
slideSize | slide-size | string | Size of each slide along the scroll axis ("100%" by default; "50%", "18rem"…). | |
slideGap | slide-gap | string | Space between slides (default var(--ray-space-4)). | |
align | align reflects | start | center | start | Where a slide snaps in the viewport. |
orientation | orientation reflects | horizontal | vertical | horizontal | Scroll axis (vertical needs a height; 20rem by default). |
loop | loop reflects | boolean | next() on the last position goes to the first, prev() on the first to the last. | |
autoplay | autoplay | number | 0 | Milliseconds between automatic moves (0: off). Pauses on hover, focus and when the page is hidden; starts paused with reduced motion. Shows a pause/play button. |
hideControls | hide-controls reflects | boolean | No previous/next buttons. | |
hideIndicators | hide-indicators reflects | boolean | No indicator dots. |
| Event | Description |
|---|---|
change | The current position changed (read `index`) by the user or a method (controls, indicators, keyboard, swipe, scroll, next/prev/goTo, autoplay) — not when `index` is set by code. |
| Slot | Description |
|---|---|
| (default) | The slides. |
| Part | Description |
|---|---|
viewport | The scrolling viewport. |
previous | The previous button. |
next | The next button. |
indicators | The row of indicator dots. |
indicator | Each indicator dot ([aria-current] on the active one). |
play | The pause/play button (with autoplay). |
Texts
What it writes itself, in English; setStrings() translates them (Getting started: Languages).
| Key | English |
|---|---|
carousel.label | Carousel |
carousel.slide | slide |
carousel.position | {index} of {count} |
carousel.previous | Previous slide |
carousel.next | Next slide |
carousel.go-to | Go to slide {index} |
carousel.play | Start autoplay |
carousel.pause | Pause autoplay |