Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

plyr

> 前端框架
Open source

A simple HTML5, YouTube and Vimeo player

29.9K stars0 likes4 views
WebsiteGitHub

About

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

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

xml
<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.

HTML5 Audio

xml
<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 `


_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.

Vimeo

Much the same as YouTube above.

xml

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.

xml
<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.

xml
<script src="https://cdn.plyr.io/3.8.4/plyr.js"></script>

...or...

xml
<script src="https://cdn.plyr.io/3.8.4/plyr.polyfilled.js"></script>

CSS

Include the plyr.css stylesheet into your <head>.

xml
<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:

xml
<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:

css
.player {
  --plyr-color-main: #1ac266;
}

...or in your HTML:

xml
<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:

javascript
const player = new Plyr(document.getElementById('player'));
javascript
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:

javascript
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:

javascript
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:

javascript
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:

xml
<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:

javascript
element.addEventListener('ready', (event) => {
  const player = event.detail.plyr;
});

Methods

Example method use:

javascript
player.play(); // Start playback
player.fullscreen.enter(); // Enter fullscreen

…

js
player.volume = 0.5; // Sets volume at 50%
player.currentTime = 10; // Seeks to 10 seconds

Example getters:

javascript
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:

javascript
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:

javascript
player.source = {
  type: 'video',
  sources: [
    {
      src: 'bTqVqk7FSmY',
      provider: 'youtube',
    },
  ],
};

Vimeo example

javascript
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:

  • Media type ('audio' | 'video')
  • Provider ('html5' | 'youtube' | 'vimeo')

Disable support programmatically

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:

javascript
{
  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.

Plugins & Components

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

Issues· 936 open

View all issuesOpen on GitHub
  • #2908

    Migrating to Video.js v10

    Updated Aug 14, 2026
  • #2903

    destroy() is a no-op before ready, leaving pending provider setup alive

    Updated Aug 6, 2026
  • #930

    full screen don't cover whole mobile screen

    Updated Jul 21, 2026
  • #2902

    Video playback fails on iPad and latest Safari

    Updated Jul 14, 2026
  • #1275

    YouTube video playing on browser but not on electron-js app

    Updated Jul 11, 2026
  • #2897

    Display incorrect duration for MP3 file in Safari on MacBook

    Updated Jun 30, 2026
  • #2898

    Audio caption

    Updated Jun 11, 2026
  • #1345

    Keyboard shortcuts do not trigger early-listeners

    Updated May 29, 2026
  • #2896

    Youtube captions / subtitles not showing

    Updated May 27, 2026
  • #2895

    Video playing with plyr, nextjs; got AbortError: The play() request was interrupted by a call to pause()

    Updated May 16, 2026

> Tags

JavaScripthtml5-videojavascriptplyrvimeo

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架