Platform video player that wraps native <video> with custom overlay controls in shadow DOM. Progressive enhancement — native video works without JS.
Overview
A platform-native video player that wraps <video> in light DOM and renders custom overlay controls in shadow DOM. Controls fade in on interaction and auto-hide during playback. The native player is always the fallback — if JS is unavailable, <video controls> works normally with poster, captions, and fullscreen.
Single Video
Wrap a native <video> with optional <track> elements for captions.
1234567
<video-player> <video controls poster="poster.jpg" width="960" height="540"> <source src="video.mp4" type="video/mp4"> <track kind="captions" src="en.vtt" srclang="en" label="English" default> <p><a href="video.mp4" download>Download video</a></p> </video></video-player>
Sizing
Always include width and height attributes on the <video> element. These give the browser intrinsic dimensions before metadata loads, preventing layout shift — the same best practice as <img>.
For remote or large video files, the browser may not have loaded metadata (and therefore the video's native dimensions) by the time the page renders. Without dimension hints, the player collapses to zero height until the remote file responds.
The component also applies aspect-ratio: 16/9 as a CSS fallback. Once the video's actual aspect ratio is known from metadata or the poster image, it overrides the CSS default automatically. If your video is not 16:9, the width/height attributes ensure the correct ratio is used from the start.
A poster image is strongly recommended — it provides visual content before playback and helps the browser establish dimensions early.
Playlist Mode
Include a <details> with <ol class="track-list"> inside the component. Clicking a track updates the video source and plays it. Use data-poster and data-captions on track links for per-video switching.
12345678910111213141516171819
<video-player> <video controls poster="ep1.jpg" width="960" height="540"> <source src="episodes/01.mp4" type="video/mp4"> <track kind="captions" src="captions/01-en.vtt" srclang="en" label="English" default> </video> <details> <summary>Episodes</summary> <ol class="track-list"> <li data-video-active> <a href="episodes/01.mp4" data-poster="ep1.jpg" data-captions="captions/01-en.vtt">01. Introduction</a> <span class="track-meta"><time datetime="PT12M30S">12:30</time></span> </li> <li> <a href="episodes/02.mp4" data-poster="ep2.jpg">02. Getting Started</a> <span class="track-meta"><time datetime="PT18M45S">18:45</time></span> </li> </ol> </details></video-player>
Shuffle and Loop
12345678910111213
<video-player shuffle loop> <video controls poster="ep1.jpg" width="960" height="540"> <source src="episodes/01.mp4" type="video/mp4"> </video> <details open> <summary>Shuffle Playlist</summary> <ol class="track-list"> <li data-video-active><a href="episodes/01.mp4">Episode 1</a></li> <li><a href="episodes/02.mp4">Episode 2</a></li> <li><a href="episodes/03.mp4">Episode 3</a></li> </ol> </details></video-player>
Controls Behavior
Unlike <audio-player> which shows a permanent control bar, video controls are an overlay that fades in and out:
- Visible for 3 seconds after any interaction (mousemove, focus, keypress)
- Never hidden while keyboard focus is inside the controls
- Always visible when paused, before first play, or after ended
- Touch devices: tap toggles visibility
- Cursor hides when controls are hidden during playback
prefers-reduced-motion: controls stay permanently visible
A gradient scrim at the bottom ensures controls are readable over any video content.
Attributes
| Attribute | Type | Description |
autoplay | Boolean | Start playing when first connected (subject to browser autoplay policy). Skipped for users with prefers-reduced-motion: reduce, which also cancels a native autoplay on the inner <video>. Not re-run when the player is moved in the DOM. |
loop | Boolean | Single video: loop it. Playlist: wrap to the first track after the last |
shuffle | Boolean | Playlist: advance to a random other track |
muted | Boolean | Start muted (an authored <video muted> works too) |
captions | Boolean | Start with the first captions/subtitles track showing |
data-label-* | String | Override any UI string; see Localization |
Component-Managed Attributes
| Attribute | Values | Description |
state | idle, playing, paused, buffering, ended | Current playback state |
data-upgraded | Present | Component has initialized |
data-fullscreen | Present | This player (not just any element on the page) is fullscreen |
captions | Present | Captions are currently showing |
controls | Present | Overlay controls are visible |
muted | Present | Audio is muted |
role, aria-label, aria-keyshortcuts, tabindex | group, "Video player", key list, 0 | Make the host a named keyboard target; authored values are kept |
Localization
Every control name and announcement is an English default that you can override with a data-label-* attribute on the host. Times and numbers use the locale of the closest [lang] (via Intl.DurationFormat, falling back to Intl.NumberFormat), so Arabic-Indic digits, for example, appear automatically.
| Attribute | Default |
data-label-player | Video player |
data-label-controls | Video controls |
data-label-play-video | Play video |
data-label-play / data-label-pause | Play / Pause |
data-label-seek | Seek |
data-label-skip-back / data-label-skip-forward | Skip back 10 seconds / Skip forward 10 seconds |
data-label-mute | Mute |
data-label-volume | Volume |
data-label-speed | Playback speed {rate} |
data-label-captions | Captions |
data-label-fullscreen / data-label-exit-fullscreen | Fullscreen / Exit fullscreen |
data-label-playing, -paused, -ended, -buffering | Status announcements |
data-label-time-of | {current} of {duration} |
1234567
<video-player lang="fr" data-label-player="Lecteur vidéo" data-label-play="Lire" data-label-pause="Pause" data-label-mute="Couper le son" data-label-time-of="{current} sur {duration}"> <video controls width="960" height="540">…</video></video-player>
The controls bar is always laid out left-to-right, also on right-to-left pages, because the timeline runs from the start to the end of the media like every platform player.
CSS Custom Properties
| Property | Default | Description |
--video-player-accent | var(--color-primary) | Play button, timeline fill, active states |
--video-player-controls-text | #fff | Controls text and icon color |
--video-player-radius | var(--radius-m) | Player border radius |
--video-player-border | none | Player border (off by default) |
--video-player-shadow | none | Player box shadow (opt-in) |
--video-player-controls-padding | var(--size-xs) var(--size-s) | Controls area padding |
--video-player-overlay-bg | oklch(0% 0 0 / 0.4) | Center play button backdrop |
--video-player-timeline-height | 4px | Timeline track height |
--video-player-timeline-buffer | oklch(100% 0 0 / 0.3) | Buffer progress color |
Video controls overlay the content, so defaults are semi-transparent dark with white text (unlike <audio-player> which uses surface/text tokens).
123456
video-player { --video-player-accent: oklch(60% 0.2 30); --video-player-radius: var(--radius-l); --video-player-shadow: var(--shadow-l); --video-player-timeline-height: 6px;}
Shadow Parts
| Part | Description |
player | Outer player container (position: relative wrapper) |
controls | Controls overlay at bottom |
play-overlay | Big center play button |
play-button | Play/pause button in controls row |
timeline | Seek range input |
mute-button | Mute toggle (aria-pressed) |
volume | Volume range input |
time-display | Current time / duration display |
speed-button | Playback speed cycle button |
captions-button | Captions toggle button |
fullscreen-button | Fullscreen toggle button |
Events
| Event | Detail |
video-player:play | { currentTime, src } |
video-player:pause | { currentTime } |
video-player:ended | { src } |
video-player:track-change | { src, title } |
video-player:fullscreen | { active: boolean } |
video-player:speed | { rate: number } |
video-player:captions | { active: boolean, label: string } |
video-player:src-changed | { src, source: 'property' } (fired when the src property is set) |
1234567891011121314151617
const player = document.querySelector('video-player'); player.addEventListener('video-player:play', (e) => { console.log('Playing:', e.detail.src);}); player.addEventListener('video-player:track-change', (e) => { console.log('Now playing:', e.detail.title);}); player.addEventListener('video-player:fullscreen', (e) => { console.log('Fullscreen:', e.detail.active);}); player.addEventListener('video-player:speed', (e) => { console.log('Speed:', e.detail.rate);});
Properties
| Property | Type | Description |
src | String | Get/set the inner video source; setting loads it and fires video-player:src-changed |
currentTime | Number | Playback position in seconds |
Keyboard Shortcuts
Shortcuts work while the player itself has focus (it is a tab stop). When focus is on one of its controls, that control keeps its own keys, and key chords with Ctrl, Cmd or Alt are never intercepted.
| Key | Action |
| Space / K | Play / Pause |
| Left Arrow | Seek back 10 seconds |
| Right Arrow | Seek forward 10 seconds |
| Up Arrow | Volume up 5% |
| Down Arrow | Volume down 5% |
| M | Toggle mute |
| F | Toggle fullscreen |
| C | Toggle captions |
| Escape | Exit fullscreen (browser default) |
On the sliders
| Control | Keys |
| Seek slider | Left/Down back 5 seconds, Right/Up forward 5 seconds; Home, End, Page Up, Page Down as native |
| Volume slider | Native: arrows change volume in 5% steps |
Progressive Enhancement
The <video> element lives in light DOM and is visible via <slot> (not hidden like <audio>). Before JS loads, native controls render with poster and captions. After the component upgrades, native controls are hidden and custom overlay chrome takes over. If the component is removed from the DOM, native controls are restored.
123456789
<video-player> <video controls poster="poster.jpg" width="960" height="540"> <source src="video.mp4" type="video/mp4"> <track kind="captions" src="en.vtt" srclang="en" label="English" default> <p><a href="video.mp4" download>Download video</a></p> </video></video-player>
Track List Data Attributes
<li> elements in .track-list use data attributes for state:
| Attribute | Set by | Meaning |
data-video-active | Component + author | Currently loaded/playing track |
data-video-played | Component | Track has been played this session |
Track <a> elements support optional attributes for per-track switching:
| Attribute | Description |
data-poster | Poster image URL for this track |
data-captions | Captions VTT file URL for this track |
Accessibility
- The host is a focusable
role="group" named "Video player", with aria-keyshortcuts listing its shortcuts
- All controls use native
<button> or <input type="range"> with aria-label; the controls bar is a labelled role="group"
- Seek slider
aria-valuetext reads "0:05 of 3:20"; the volume slider reads a percentage, e.g. "37%"
- Mute and captions buttons use
aria-pressed to reflect state
- The big play button is only focusable while it is visible (idle and ended); otherwise it is
inert
- Auto-hide never hides the controls while focus is inside them
- The speed button's name carries the current rate ("Playback speed 1.5x"); a change made with the button is announced once, politely
- Hidden
role="status" region announces "Playing", "Paused", "Ended", "Buffering"
- Respects
prefers-reduced-motion: no autoplay, no transitions, controls stay visible
- Forced colours: progress and volume fills use system colours (
Highlight), tracks are outlined
- Falls back to fully accessible native
<video> without JS
- Captions rendered by native
<video> and styled with the video::cue hooks
Fullscreen
Fullscreen is requested on the host element (not the <video>), so the custom shadow DOM controls remain visible in fullscreen mode. The <video> fills the host via CSS. Fullscreen state is tracked per player: only the player that is actually fullscreen sets data-fullscreen and fires video-player:fullscreen.
Related
<video> — Native video element (Layers 1-3)
<audio-player> — Audio equivalent with same architecture
<youtube-player> — YouTube embed with facade pattern (no <video> element)
<track> — Captions, subtitles, and chapter tracks
controls — The browser's built-in media controls
poster — The poster image; also set through data-poster
preload — How much media to download before play