Skip to content
FrameworkStyle

youtube-video

Video component that plays YouTube videos and playlists through the YouTube IFrame player

Video component that plays YouTube videos and playlists through the YouTube IFrame player. YouTube’s own chrome stays hidden by default, so it drops into a player skin like any other media component; set controls to use YouTube’s UI instead.

Load a source

src takes a YouTube URL or a raw 11-character video id. Watch, share (youtu.be), embed, Shorts, live, and privacy-enhanced (youtube-nocookie.com) URLs all work. Playlist URLs load through their list parameter, and a t parameter sets the start position.

<youtube-video src="https://www.youtube.com/watch?v=aqz-KE-bpKQ"></youtube-video>

Behavior

A few things work differently from a native <video> element, because the IFrame API doesn’t expose them:

  • loop restarts playback when the video ends; the IFrame API has no single-video loop.
  • Fullscreen targets the iframe, so YouTube’s own chrome shows in fullscreen.
  • Picture-in-picture is unavailable, and the player reports it as unsupported.
  • Caption tracks appear in textTracks once playback starts; YouTube reports no caption metadata before then.

Examples

Basic Usage

<youtube-video
    class="youtube-video"
    src="https://www.youtube.com/watch?v=aqz-KE-bpKQ"
    controls
></youtube-video>

API Reference

Attributes

These attributes configure the embedded media adapter:

AttributeTypeDefaultDetails
autoplayboolean
controlsboolean
loopboolean
mutedboolean
playsinlineboolean
posterstring
preloadMediaPreloadType
srcstring

Properties

PropertyTypeDefaultDetails
autoplayboolean
bufferedTimeRangeLike
controlsboolean
currentSrcstring
currentTimenumber
defaultMutedboolean
durationnumber
endedboolean
engineYouTubePlayerApi | null
errorMediaError | null
isFullscreenboolean
loopboolean
mutedboolean
pausedboolean
playbackRatenumber
playsInlineboolean
posterstring
preloadMediaPreloadType
readyStatenumber
seekableTimeRangeLike
seekingboolean
sourceYouTubeSource | null
srcstring
textTracksTextTrackListLike
volumenumber

Engine options

source.engine.youtube

Pass YouTube player parameters under source.engine.youtube, spelled exactly as YouTube spells them. They’re serialized onto the embed URL untouched, and the embed reads them once, when its URL is built. Media Sources covers how engine options fit into a structured source.

autoplay, controls, and playsinline come from the props of the same name, so they have no engine.youtube spelling. Parameters YouTube has deprecated are absent as well: modestbranding, showinfo, autohide, theme, and listType: 'search'. Anything YouTube adds next passes through the same way.

const video = document.querySelector('youtube-video');
video.source = {
  src: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
  engine: { youtube: { hl: 'de', cc_load_policy: 1 } },
};
OptionTypeDetails
cc_lang_prefstring
cc_load_policy1
color"red" | "white"
disablekb0 | 1
enablejsapi0 | 1
endnumber
fs0 | 1
hlstring
iv_load_policy1 | 3
liststring
listType"playlist" | "user_uploads"
loop0 | 1
originstring
playliststring
referrerPolicyReferrerPolicy
rel0 | 1
startnumber
widget_referrerstring

Methods

Supports these media methods: exitFullscreenloadpauseplayrequestFullscreen

Events

Implements these standard media events through the embedded player: durationchangeemptiedendederrorloadedmetadataloadstartpauseplayplayingprogressratechangeseekedseekingtimeupdatevolumechangewaiting

Also emits these Video.js-specific events:

EventDescription
loadcomplete
sourcechange