A simple HTML5, YouTube and Vimeo player
Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports modern browsers.
Checkout the demo - Donate - Slack - Video hosting
<input type="range"> for volume and <progress> for progress and well, <button>s for buttons. There's no
<span> or <a href="#"> button hacksplaysinline attributeYou can try Plyr in Codepen using our minimal templates: HTML5 video, HTML5 audio, YouTube, Vimeo. For Streaming we also have example integrations with: Dash.js, Hls.js and Shaka Player
Plyr extends upon the standard HTML5 media element markup so that's all you need for those types.
<video id="player" playsinline controls data-poster="/path/to/poster.jpg">
<source src="/path/to/video.mp4" type="video/mp4" />
<source src="/path/to/video.webm" type="video/webm" />
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default />
</video>Note: The poster image should be specified using data-poster. This is to prevent it being downloaded twice. If you're sure the image will be cached, you can still use the poster attribute for true progressive enhancement.
<audio id="player" controls>
<source src="/path/to/audio.mp3" type="audio/mp3" />
<source src="/path/to/audio.ogg" type="audio/ogg" />
</audio>For YouTube and Vimeo players, Plyr uses progressive enhancement to enhance the default <iframe> embeds. Below are some examples. The plyr__video-embed classname will make the embed responsive. You can add the autoplay, loop, hl (YouTube only) and playsinline (YouTube only) query parameters to the URL and they will be set as config options automatically. For YouTube, the origin should be updated to reflect the domain you're hosting the embed on, or you can opt to omit it.
We recommend progressive enhancement with the embedded players. You can elect to use an <iframe> as the source element (which Plyr will progressively enhance) or a bog standard `
_Note_: The `plyr__video-embed` classname will make the player a responsive 16:9 (most common) iframe embed. When plyr itself kicks in, your custom `ratio` config option will be used.
Or the `
Note: The data-plyr-embed-id can either be the video ID or URL for the media.
Much the same as YouTube above.
Or the `
## JavaScript
You can use Plyr as an ES6 module as follows:
```js
import Plyr from 'plyr';
const player = new Plyr('#player');Alternatively you can include the plyr.js script before the closing </body> tag and then in your JS create a new instance of Plyr as below.
<script src="path/to/plyr.js"></script>
<script>
const player = new Plyr('#player');
</script>See initialising for more information on advanced setups.
You can use our CDN (provided by Cloudflare) for the JavaScript. There's 2 versions; one with and one without polyfills. My recommendation would be to manage polyfills separately as part of your application but to make life easier you can use the polyfilled build.
<script src="https://cdn.plyr.io/3.8.4/plyr.js"></script>...or...
<script src="https://cdn.plyr.io/3.8.4/plyr.polyfilled.js"></script>Include the plyr.css stylesheet into your <head>.
<link rel="stylesheet" href="path/to/plyr.css" />If you want to use our CDN (provided by Cloudflare) for the default CSS, you can use the following:
<link rel="stylesheet" href="https://cdn.plyr.io/3.8.4/plyr.css" />
…
css
:root {
--plyr-color-main: #1ac266;
}...or for a specific class name:
.player {
--plyr-color-main: #1ac266;
}...or in your HTML:
<video class="player" style="--plyr-color-main: #1ac266;">...</video>
…
js
const player = new Plyr(video, {
previewThumbnails: {
enabled: true,
src: 'https://cdn.example.com/storyboard.vtt',
withCredentials: true,
},
});
…
js
const player = new Plyr('#player');Passing a HTMLElement:
const player = new Plyr(document.getElementById('player'));const player = new Plyr(document.querySelector('.js-player'));The HTMLElement or string selector can be the target <video>, <audio>, or <div> wrapper for embeds.
You have two choices here. You can either use a simple array loop to map the constructor:
const players = Array.from(document.querySelectorAll('.js-player')).map((p) => new Plyr(p));...or use a static method where you can pass a CSS string selector, a NodeList, an Array of HTMLElement, or a JQuery object:
const players = Plyr.setup('.js-player');Both options will also return an array of instances in the order of they were in the DOM for the string selector or the source NodeList or Array.
The second argument for the constructor is the options object:
const player = new Plyr('#player', {
title: 'Example Title',
});Options can be passed as an object to the constructor as above or as JSON in data-plyr-config attribute on each of your target elements:
<video src="/path/to/video.mp4" id="player" controls data-plyr-config='{ "title": "Example Title" }'></video>
…
js
const player = new Plyr('#player', {
/* options */
});You can also access the object through any events:
element.addEventListener('ready', (event) => {
const player = event.detail.plyr;
});Example method use:
player.play(); // Start playback
player.fullscreen.enter(); // Enter fullscreen
…
js
player.volume = 0.5; // Sets volume at 50%
player.currentTime = 10; // Seeks to 10 secondsExample getters:
player.volume; // 0.5;
player.currentTime; // 10
player.fullscreen.active; // false;
…
js
player.source = {
type: 'video',
title: 'Example title',
sources: [
{
src: '/path/to/movie.mp4',
type: 'video/mp4',
size: 720,
},
{
src: '/path/to/movie.webm',
type: 'video/webm',
size: 1080,
},
],
poster: '/path/to/poster.jpg',
previewThumbnails: {
src: '/path/to/thumbnails.vtt',
},
tracks: [
{
kind: 'captions',
label: 'English',
srclang: 'en',
src: '/path/to/captions.en.vtt',
default: true,
},
{
kind: 'captions',
label: 'French',
srclang: 'fr',
src: '/path/to/captions.fr.vtt',
},
],
};Audio example:
player.source = {
type: 'audio',
title: 'Example title',
sources: [
{
src: '/path/to/audio.mp3',
type: 'audio/mp3',
},
{
src: '/path/to/audio.ogg',
type: 'audio/ogg',
},
],
};YouTube example:
player.source = {
type: 'video',
sources: [
{
src: 'bTqVqk7FSmY',
provider: 'youtube',
},
],
};Vimeo example
player.source = {
type: 'video',
sources: [
{
src: '76979871',
provider: 'vimeo',
},
],
};
…
js
player.on('ready', (event) => {
const instance = event.detail.plyr;
});
…
js
const supported = Plyr.supported('video', 'html5');The arguments are:
'audio' | 'video')'html5' | 'youtube' | 'vimeo')The enabled option can be used to disable certain User Agents. For example, if you don't want to use Plyr for smartphones, you could use:
{
enabled: !/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
}If a User Agent is disabled but supports <video> and <audio> natively, it will use the native player.
Some awesome folks have made plugins for CMSs and Components for JavaScript frameworks:
| Type | Maintainer | Link |
|---|---|---|
| WordPress | Brandon Lavigne (@drrobotnik) | https://wordpress.org/plugins/plyr/ |
| Angular | Simon Bobrov (@smnbbrv) | https://github.com/smnbbrv/ngx-plyr |
| React | Chintan Prajapati (@chintan9) | https://github.com/chintan9/plyr-react |
| Vue | Gabe Dunn (@redxtech) | https://github.com/redxtech/vue-plyr |
| Neos | Jon Uhlmann (@jonnitto) | https://packagist.org/packages/jonnitto/plyr |
| Kirby | Dominik Pschenitschni (@dpschen) | https://github.com/dpschen/kirby-plyrtag |
| REDAXO | FriendsOfRedaxo / skerbis |
Migrating to Video.js v10
destroy() is a no-op before ready, leaving pending provider setup alive
full screen don't cover whole mobile screen
Video playback fails on iPad and latest Safari
YouTube video playing on browser but not on electron-js app
Display incorrect duration for MP3 file in Safari on MacBook
Audio caption
Keyboard shortcuts do not trigger early-listeners
Youtube captions / subtitles not showing
Video playing with plyr, nextjs; got AbortError: The play() request was interrupted by a call to pause()