Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports modern browsers.
Checkout the demo - Donate - Slack -


Features
- ? HTML Video & Audio, YouTube & Vimeo - support for the major formats
- ? Accessible - full support for VTT captions and screen readers
- ? Customizable - make the player look how you want with the markup you want
- ? Clean HTML - uses the right elements.
<input type="range">
for volume and <progress>
for progress and well, <button>
s for buttons. There's no
<span>
or <a href="#">
button hacks
- ? Responsive - works with any screen size
- ? Monetization - make money from your videos
- ? Streaming - support for hls.js, Shaka and dash.js streaming playback
- ? API - toggle playback, volume, seeking, and more through a standardized API
- ? Events - no messing around with Vimeo and YouTube APIs, all events are standardized across formats
- ? Fullscreen - supports native fullscreen with fallback to "full window" modes
- ⌨️ Shortcuts - supports keyboard shortcuts
- ? Picture-in-Picture - supports picture-in-picture mode
- ? Playsinline - supports the
playsinline
attribute
- ? Speed controls - adjust speed on the fly
- ? Multiple captions - support for multiple caption tracks
- ? i18n support - support for internationalization of controls
- ? Preview thumbnails - support for displaying preview thumbnails
- ? No frameworks - written in "vanilla" ES6 JavaScript, no jQuery required
- ?♀️ SASS - to include in your build processes
Demos
You 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
Quick setup
HTML
Plyr extends upon the standard HTML5 media element markup so that's all you need for those types.
HTML5 Video
<video poster="/path/to/poster.jpg" id="player" playsinline controls>
<source src="/path/to/video.mp4" type="video/mp4" />
<source src="/path/to/video.webm" type="video/webm" />
<!-- Captions are optional -->
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default />
</video>
HTML5 Audio
<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.
YouTube
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 <div>
with two essential data attributes - data-plyr-provider
and data-plyr-embed-id
.
<div class="plyr__video-embed" id="player">
<iframe
src="https://www.youtube.com/embed/bTqVqk7FSmY?origin=https://plyr.io&iv_load_policy=3&modestbranding=1&playsinline=1&showinfo=0&rel=0&enablejsapi=1"
allowfullscreen
allowtransparency
allow="autoplay"
></iframe>
</div>
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 <div>
non progressively enhanced method:
<div id="player" data-plyr-provider="youtube" data-plyr-embed-id="bTqVqk7FSmY"></div>
Note: The data-plyr-embed-id
can either be the video ID or URL for the media.
Vimeo
Much the same as YouTube above.
<div class="plyr__video-embed" id="player">
<iframe
src="https://player.vimeo.com/video/76979871?loop=false&byline=false&portrait=false&title=false&speed=true&transparent=0&gesture=media"
allowfullscreen
allowtransparency
allow="autoplay"
></iframe>
</div>
Or the <div>
non progressively enhanced method:
<div id="player" data-plyr-provider="vimeo" data-plyr-embed-id="76979871"></div>
JavaScript
You can use Plyr as an ES6 module as follows:
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 Fastly) for the JavaScript. There's 2 versions; one with and one without polyfills. My recommendation would be to manage polyfills seperately as part of your application but to make life easier you can use the polyfilled build.
<script src="https://cdn.plyr.io/3.5.10/plyr.js"></script>
...or...
<script src="https://cdn.plyr.io/3.5.10/plyr.polyfilled.js"></script>
CSS
Include the plyr.css
stylsheet into your <head>
.
<link rel="stylesheet" href="path/to/plyr.css" />
If you want to use our CDN (provided by Fastly) for the default CSS, you can use the following:
<link rel="stylesheet" href="https://cdn.plyr.io/3.5.10/plyr.css" />
SVG Sprite
The SVG sprite is loaded automatically from our CDN (provided by Fastly). To change this, see the options below. For
reference, the CDN hosted SVG sprite can be found at https://cdn.plyr.io/3.5.10/plyr.svg
.
Ads
Plyr has partnered up with vi.ai to offer monetization options for your videos. Getting setup is easy:
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
Advanced
SASS
You can use bundle.scss
file included in /src
as part of your build and change variables to suit your design. The SASS require you to
use the autoprefixer plugin (you should be already!) as all declarations use the W3C definitions.
The HTML markup uses the BEM methodology with plyr
as the block, e.g. .plyr__controls
. You can change the class hooks in the options to match any custom CSS
you write. Check out the JavaScript source for more on this.
SVG
The icons used in the Plyr controls are loaded in an SVG sprite. The sprite is automatically loaded from our CDN by default. If you already have an icon build
system in place, you can include the source plyr icons (see /src/sprite
for source icons).
Using the iconUrl
option
You can however specify your own iconUrl
option and Plyr will determine if the url is absolute and requires loading by AJAX/CORS due to current browser
limitations or if it's a relative path, just use the path directly.
If you're using the <base>
tag on your site, you may need to use something like this: svgfixer.js
More info on SVG sprites here: http://css-tricks.com/svg-sprites-use-better-icon-fonts/ and the AJAX
technique here: http://css-tricks.com/ajaxing-svg-sprite/
Cross Origin (CORS)
You'll notice the crossorigin
attribute on the example <video>
elements. This is because the TextTrack captions are loaded from another domain. If your
TextTrack captions are also hosted on another domain, you will need to add this attribute and make sure your host has the correct headers setup. For more info
on CORS checkout the MDN docs:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
Captions
WebVTT captions are supported. To add a caption track, check the HTML example above and look for the <track>
element. Be sure to
validate your caption files.
JavaScript
Initialising
You can specify a range of arguments for the constructor to use:
Note: If a NodeList
, Array
, or jQuery object are passed, the first element will be used for setup. To setup multiple players, see multiple players below.
Single player
Passing a CSS string selector that's compatible with querySelector
:
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.
Multiple players
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.
Options
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>
Note the single quotes encapsulating the JSON and double quotes on the object keys. Only string values need double quotes.