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.
<YouTubeVideo src="https://www.youtube.com/watch?v=aqz-KE-bpKQ" /><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:
looprestarts 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
textTracksonce playback starts; YouTube reports no caption metadata before then.
Examples
Basic Usage
import { YouTubeVideo } from '@videojs/react/media/youtube-video';
export default function BasicUsage() {
return (
<div className="youtube-video">
<YouTubeVideo src="https://www.youtube.com/watch?v=aqz-KE-bpKQ" controls />
</div>
);
}
.youtube-video {
width: 100%;
aspect-ratio: 16 / 9;
}
<youtube-video
class="youtube-video"
src="https://www.youtube.com/watch?v=aqz-KE-bpKQ"
controls
></youtube-video>
.youtube-video {
width: 100%;
aspect-ratio: 16 / 9;
}
import '@videojs/html/media/youtube-video';
API Reference
Attributes
These attributes configure the embedded media adapter:
| Attribute | Type | Default | Details |
|---|---|---|---|
autoplay | boolean | — | |
controls | boolean | — | |
loop | boolean | — | |
muted | boolean | — | |
playsinline | boolean | — | |
poster | string | — | |
preload | MediaPreloadType | — | |
src | string | — |
Properties
| Property | Type | Default | Details |
|---|---|---|---|
autoplay | boolean | — | |
buffered | TimeRangeLike | — | |
| |||
controls | boolean | — | |
currentSrc | string | — | |
| |||
currentTime | number | — | |
defaultMuted | boolean | — | |
duration | number | — | |
| |||
ended | boolean | — | |
| |||
engine | YouTubePlayerApi | null | — | |
| |||
error | MediaError | null | — | |
| |||
isFullscreen | boolean | — | |
| |||
loop | boolean | — | |
muted | boolean | — | |
paused | boolean | — | |
| |||
playbackRate | number | — | |
playsInline | boolean | — | |
poster | string | — | |
preload | MediaPreloadType | — | |
readyState | number | — | |
| |||
seekable | TimeRangeLike | — | |
| |||
seeking | boolean | — | |
| |||
source | YouTubeSource | null | — | |
| |||
src | string | — | |
textTracks | TextTrackListLike | — | |
| |||
volume | number | — | |
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.
<YouTubeVideo
source={{
src: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
engine: { youtube: { hl: 'de', cc_load_policy: 1 } },
}}
/>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 } },
};| Option | Type | Details |
|---|---|---|
cc_lang_pref | string | |
| ||
cc_load_policy | 1 | |
| ||
color | "red" | "white" | |
| ||
disablekb | 0 | 1 | |
| ||
enablejsapi | 0 | 1 | |
| ||
end | number | |
| ||
fs | 0 | 1 | |
| ||
hl | string | |
| ||
iv_load_policy | 1 | 3 | |
| ||
list | string | |
| ||
listType | "playlist" | "user_uploads" | |
| ||
loop | 0 | 1 | |
| ||
origin | string | |
| ||
playlist | string | |
| ||
referrerPolicy | ReferrerPolicy | |
| ||
rel | 0 | 1 | |
| ||
start | number | |
| ||
widget_referrer | string | |
| ||
Methods
Supports these media methods: exitFullscreenloadpauseplayrequestFullscreen
Events
Implements these standard media events through the embedded player: durationchangeemptiedendederrorloadedmetadataloadstartpauseplayplayingprogressratechangeseekedseekingtimeupdatevolumechangewaiting
Also emits these Video.js-specific events:
| Event | Description |
|---|---|
loadcomplete | |
sourcechange |