A vertical card that plays photo and video slides one after another, like stories in a social app. Tap the left third to go back, the rest to go forward, press and hold to pause. The segment fill is a CSS animation, so there is no timer ticking on every frame, and a small client script only handles taps, keys, visibility and video.
Browser Support
Baseline Widely available2 featuresDetails
Slides that are not on screen are inert, so Tab and screen readers skip them. Without support they stay hidden with visibility, so only focus order is affected.
Autoplay runs only while the player is visible. Without support the player plays as soon as it is mounted.
Preview

First light
Clouds fill the valley before sunrise

The long way down
A glacier valley, five hours in
Sun over the hills
Eleven seconds of a real video

Above the snow line
The air gets thin and quiet

Last stop: the lake
Worth every step
Installation
Usage
import { StoryPlayer } from "@/components/ui/story-player"
const slides = [
{ src: "/stories/dawn.webp", title: "First light", alt: "Clouds in a valley" },
{ src: "/stories/hills.mp4", title: "Sun over the hills" },
{ src: "/stories/lake.webp", duration: 7000 },
]
export default function Example() {
return (
<StoryPlayer
slides={slides}
author="Mei Tanaka"
avatar="/avatars/mei.webp"
meta="2h"
className="max-w-[340px]"
/>
)
}Examples
Video slide and per-slide duration
The type is detected from the extension (or set type). A video is muted and its slide lasts as long as the file; a photo takes duration, and a slide can override it with its own duration.
Sun over the hills
A video slide takes its length from the file

Above the snow line
A photo slide lasts 3 seconds here
const slides = [
{ src: "/stories/hills.mp4", poster: "/stories/hills.webp" }, // length of the file
{ src: "/stories/peaks.webp", duration: 3000 },
]
<StoryPlayer slides={slides} author="Mei Tanaka" />Transitions
transition accepts "fade" (default), "slide" and "blur". Three players side by side, each with 3-second slides.
Fade

First light
Clouds fill the valley before sunrise

The long way down
A glacier valley, five hours in

Above the snow line
The air gets thin and quiet

Last stop: the lake
Worth every step
Slide

First light
Clouds fill the valley before sunrise

The long way down
A glacier valley, five hours in

Above the snow line
The air gets thin and quiet

Last stop: the lake
Worth every step
Blur

First light
Clouds fill the valley before sunrise

The long way down
A glacier valley, five hours in

Above the snow line
The air gets thin and quiet

Last stop: the lake
Worth every step
<StoryPlayer slides={slides} author="Mei" transition="slide" duration={3000} className="w-44" />
{/* "fade" | "slide" | "blur" */}Manual control with a ref
With autoplay={false} the player waits. A ref exposes next, prev, goTo, play and pause, and onChange and onEnd report progress. Here loop is off, so the last slide fires onEnd.

First light
Clouds fill the valley before sunrise

The long way down
A glacier valley, five hours in
Sun over the hills
Eleven seconds of a real video

Above the snow line
The air gets thin and quiet

Last stop: the lake
Worth every step
Slide 1 / 5
const ref = React.useRef<StoryPlayerHandle>(null)
<StoryPlayer
ref={ref}
slides={slides}
author="Mei Tanaka"
autoplay={false}
loop={false}
onChange={(index) => console.log(index)}
onEnd={() => console.log("done")}
/>
<Button onClick={() => ref.current?.play()}>Play</Button>
<Button onClick={() => ref.current?.goTo(2)}>Go to 3</Button>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| slides | StoryPlayerSlide[] | - | Slides to play (required) |
| author | string | - | Name in the header (required) |
| avatar | string | - | Avatar URL. Without it the initials of the author are shown |
| meta | string | - | Small text next to the name, e.g. "2h" |
| duration | number | 5000 | Default time per photo slide in milliseconds |
| autoplay | boolean | true | Play while the player is on screen. Off under reduced motion until play() or the button |
| loop | boolean | true | Start over after the last slide. When off, onEnd is called and the player stops |
| transition | "fade" | "slide" | "blur" | "fade" | How slides change |
| kenBurns | boolean | true | Slow zoom and drift of photos (CSS) |
| labels | Partial<StoryPlayerLabels> | - | Texts, all optional, English by default |
| onChange | (index: number) => void | - | Called with the new index when the slide changes |
| onEnd | () => void | - | Called after the last slide when loop is off |
| ref | Ref<StoryPlayerHandle> | - | Handle with next, prev, goTo, play and pause |
| className | string | - | Extra classes. The width follows the container up to max-w-[340px]; override it here. The height comes from aspect-9/16 |
Slide fields
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | Image or video URL (required) |
| type | "image" | "video" | by extension | mp4, webm, mov, m4v and ogv count as video |
| title | string | - | Caption at the bottom |
| subtitle | string | - | Smaller line under the title |
| duration | number | duration prop or video length | Milliseconds for this slide |
| alt | string | title | Alt text of an image, accessible name of a video |
| poster | string | - | Poster of a video slide |
Labels
story, roleDescription, previous, next, pause, play and slide. The slide template replaces {current} and {total}.
Accessibility
- The player is a group with aria-roledescription="story" and the name "Story: author". Each slide is a group named "Slide N of M"; slides that are not current are inert.
- Tap zones are real buttons with labels, so Tab and Enter work. With focus on the player, the arrow keys go back and forward and Space pauses or resumes.
- A visible pause button is always in the header and changes its label to Play.
- A polite live region announces Slide N of M only after manual navigation (tap, keys, ref), so autoplay does not talk over a screen reader.
- Images take alt from alt or the title; a video takes it as its accessible name. Avatars are decorative.
Reduced motion and pausing
- With prefers-reduced-motion: reduce the Ken Burns drift is removed and slides switch without a transition.
- Autoplay is off by default under reduced motion: the player starts on the first slide with the active segment shown filled, and navigation is manual. play(), Space or the pause button start it on purpose.
- Autoplay also waits until the player is at least a quarter visible and pauses when the tab is hidden.
- Holding a press on a tap zone for about 200 ms pauses the timer and the video; releasing resumes and is not counted as a tap.
Notes
- The progress is the source of truth: a video that stalls shows as buffering and pauses the fill, but a video may drift by a fraction of a second from the segment.
- Callbacks are plain functions, so pass them from a client component.
- Photos load lazily and the next slide is preloaded. Use 720x1280 images for a 340 px card.