Accessible video player with support for YouTube, Vimeo, and self-hosted videos
<link rel="stylesheet" href="styles/video-player.css">
<script src="javascript/video-player.js"></script>
<!-- YouTube Video -->
<div class="rsl-video-player"
data-rsl-video
data-video-src="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
data-video-poster="thumbnail.jpg"
data-video-title="My Video">
</div>
<!-- Self-Hosted Video -->
<div class="rsl-video-player"
data-rsl-video
data-video-src="video.mp4"
data-video-poster="poster.jpg"
data-video-title="Self-Hosted Video"
data-video-captions="captions.vtt">
</div>
| Attribute | Values | Default | Description |
|---|---|---|---|
data-rsl-video |
(presence) | - | Marks element for auto-initialization |
data-video-src |
URL | Required | Video URL (YouTube, Vimeo, or direct file) |
data-video-type |
youtube | vimeo | self |
Auto-detect | Video source type (auto-detected from URL) |
data-video-poster |
URL | none | Thumbnail/poster image URL |
data-video-title |
string | "Video" | Video title for accessibility |
data-video-aspect |
16:9 | 4:3 | 1:1 | 9:16 | 21:9 |
16:9 | Video aspect ratio |
data-video-size |
sm | md | lg | full |
none | Max-width constraint |
data-video-autoplay |
true | false |
false | Auto-play when visible (requires muted) |
data-video-muted |
true | false |
false | Start video muted |
data-video-loop |
true | false |
false | Loop video playback |
data-video-controls |
true | false |
true | Show custom controls |
data-video-lazy |
true | false |
true | Lazy load video on play click |
data-video-captions |
URL | none | WebVTT caption file URL (self-hosted only) |
data-video-start |
seconds | 0 | Start time in seconds |
data-video-end |
seconds | none | End time in seconds |
data-video-category |
string | none | Category for FilterBus integration |
| Method | Parameters | Description |
|---|---|---|
RSL.VideoPlayer.init() |
- | Initialize all video players on the page |
RSL.VideoPlayer.create(element, options) |
element: HTMLElement, options: Object | Create a video player programmatically |
RSL.VideoPlayer.getInstance(element) |
element: HTMLElement | string | Get player instance for an element |
RSL.VideoPlayer.destroy(element) |
element: HTMLElement | string | Destroy a video player |
instance.play() |
- | Play the video |
instance.pause() |
- | Pause the video |
instance.seek(time) |
time: number (seconds) | Seek to specific time |
instance.setVolume(vol) |
vol: number (0-1) | Set volume level |
instance.mute() |
- | Mute audio |
instance.unmute() |
- | Unmute audio |
instance.getState() |
- | Get current player state |
// Create a video player programmatically
const player = RSL.VideoPlayer.create('#my-player', {
src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
poster: 'thumbnail.jpg',
title: 'My Video',
aspect: '16:9'
});
// Control playback
player.play();
player.pause();
player.seek(30); // Jump to 30 seconds
player.setVolume(0.5); // 50% volume
// Get current state
const state = player.getState();
console.log(state.isPlaying, state.currentTime);
The video player supports comprehensive keyboard controls for accessibility:
| Key | Action |
|---|---|
| Space or K | Play / Pause |
| ← | Seek back 5 seconds |
| → | Seek forward 5 seconds |
| J | Seek back 10 seconds |
| L | Seek forward 10 seconds |
| ↑ | Volume up 10% |
| ↓ | Volume down 10% |
| M | Toggle mute |
| F | Toggle fullscreen |
| C | Toggle captions |
| 0 - 9 | Seek to 0% - 90% of video |
| Home | Go to beginning |
| End | Go to end |
The Video Player component is built with accessibility as a core requirement, not an afterthought.
role="application" on container for keyboard capturearia-live="polite" region announces state changesaria-label attributesrole="slider" with proper ARIA attributesprefers-reduced-motionRSL provides caption display capabilities, but you are responsible for creating accurate caption files (WebVTT format) for your video content. Captions are required for WCAG 2.1 Level A compliance.
The Video Player integrates with RSL's FilterBus for creating filterable video galleries:
<!-- Filter Controls -->
<div data-rsl-filter data-filterbus-key="video-category">
<button data-filter-value="tutorials">Tutorials</button>
<button data-filter-value="demos">Demos</button>
<button data-filter-value="webinars">Webinars</button>
</div>
<!-- Video Gallery -->
<div class="slot-layout" data-cols-md="2" data-cols-lg="3">
<div class="slot-item">
<div class="rsl-video-player" data-rsl-video
data-video-src="tutorial-1.mp4"
data-video-category="tutorials"></div>
</div>
<div class="slot-item">
<div class="rsl-video-player" data-rsl-video
data-video-src="demo-1.mp4"
data-video-category="demos"></div>
</div>
</div>
View examples.html for comprehensive demos
Test features in playground.html
Browse all RSL components