0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Scroll carousel with prev/next buttons, dot indicators, autoplay, keyboard navigation, and ARIA.
Overview
A scroll-snap carousel with full progressive enhancement. Without JavaScript it renders as a simple scrollable row. With JS it adds prev/next buttons, dot indicators, autoplay, looping, keyboard navigation, and ARIA roles.
Usage
Wrap slide elements inside <carousel-wc>. Each direct child becomes a slide. Give each carousel a name with aria-label or aria-labelledby: the carousel is a region landmark, and unnamed ones all fall back to "Carousel", which makes several on one page indistinguishable.
Add autoplay and loop to cycle slides automatically. Autoplay renders a pause/play rotation control as the first control in the carousel. Pausing with it sticks until the user presses play again. While rotation is on, it also pauses while the pointer is over the carousel or keyboard focus is inside it, and resumes when they leave. When prefers-reduced-motion is active, autoplay is off entirely and no rotation control appears.
Set item-width="auto" to show multiple items at once with a gap. Each item keeps its content width. For equal widths, pass a CSS length such as item-width="18rem" or item-width="40%".
carousel-wc:play and carousel-wc:pause follow the autoplay timer. They also fire when hover or focus suspends rotation and when rotation resumes afterwards.
JavaScript API
Property / Method
Type
Description
element.currentIndex
number
Current slide index (read-only)
element.slideCount
number
Total number of slides (read-only)
element.playing
boolean
Whether the autoplay timer is running right now (read-only; false while hover or focus suspends it)
element.slides
Array
Get the slides as data, or assign records to rebuild (see Data API)
element.next()
method
Go to next slide
element.prev()
method
Go to previous slide
element.goTo(index, smooth)
method
Jump to specific slide (smooth defaults to true)
element.play()
method
Start or resume rotation, adding the rotation control if needed (no-op under reduced motion)
element.pause()
method
Stop rotation until play() or the rotation control resumes it
element.reset()
method
Return to initial slide, clear persistence
JS API
12345678910111213
const el = document.querySelector('carousel-wc');el.next(); // Go to next slideel.prev(); // Go to previous slideel.goTo(2); // Jump to slide index 2console.log(el.currentIndex); // Current slide indexconsole.log(el.slideCount); // Total slidesconsole.log(el.playing); // Autoplay active?el.pause(); // Pause autoplayel.play(); // Resume autoplayel.reset(); // Return to initial slide
Data API
The slides property swaps the slide set from data. Each record needs html (the slide content as an HTML string). id becomes the slide element's id. label replaces the default "n of total" slide label. Assigning rebuilds the carousel at slide 0 (or start) and fires carousel-wc:slides-changed. If you assign before the element is in the document, the carousel builds once when it connects.
The data API is HTML-only: content is assigned with innerHTML. Sanitize untrusted strings before you assign them.
Keyboard Navigation
Focus the carousel track (Tab into it), then use arrow keys:
Key
Action
ArrowLeft
Previous slide
ArrowRight
Next slide
Home
First slide
End
Last slide
In right-to-left documents the arrow keys follow the visual direction: ArrowLeft goes to the next slide, ArrowRight to the previous one, and the prev/next chevrons are mirrored.
Accessibility
ARIA Roles
The component uses role="region" with aria-roledescription="carousel". An authored aria-label or aria-labelledby names the region; without one it falls back to "Carousel". Each slide has role="group" with aria-roledescription="slide" and a label like "1 of 4", unless the slide already has an aria-label. The slide track is a focus stop for the arrow keys: it has role="group" and is named "Slides" (set data-label-track on the carousel to change or translate the name). Dot indicators are simple buttons inside a role="group" named "Slide indicators"; only the active dot carries aria-current="true".
Rotation Control
With autoplay, a pause/play button comes first in the carousel's reading order, following the APG carousel pattern and WCAG 2.2.2 (Pause, Stop, Hide). Its accessible name says what it will do: "Pause automatic slide show" or "Start automatic slide show".
Live Region
A visually hidden live region announces "Slide n of total". It is aria-live="off" while slides rotate on their own, so screen readers are not interrupted on every tick. It becomes aria-live="polite" when rotation is paused or suspended, and on carousels without autoplay.
Reduced Motion
When prefers-reduced-motion is active (or the page sets data-motion-reduced on the root element), autoplay is completely disabled, no rotation control is rendered, and scroll behavior uses instant transitions.
Styling
Override the button and dot styles using the .carousel-rotate, .carousel-prev, .carousel-next, and .carousel-dot classes.
Without JavaScript, <carousel-wc> renders as a horizontal scrollable row using the :not(:defined) fallback. Once JS registers the component, controls and indicators appear.
No-JS fallback
123456789101112
/* Without JS: simple horizontal scroll */carousel-wc:not(:defined) {display: flex;overflow-x: auto;gap: var(--size-s);scroll-snap-type: x mandatory;}carousel-wc:not(:defined) > * {flex: 00 auto;scroll-snap-align: start;}
View Transitions
Add transition to switch from scroll-snap to View Transition animations. When active, the carousel uses a stacked-grid layout and animates between slides using the View Transitions API.
Value
Effect
fade (default)
Crossfade between slides
slide
Directional slide — forward when advancing, backward when retreating
scale
Scale down old slide, scale up new slide
Dual-Mode Behavior
Without transition, the carousel uses scroll-snap with IntersectionObserver — slides are arranged in a horizontal row and the user scrolls between them. With transition, the carousel switches to a stacked CSS Grid layout where slides occupy the same grid cell and are shown/hidden with View Transition animations.
Related
<layout-reel> — CSS-only horizontal scroll with snap