Youtube Background Video
YouTube Backgrounds
Play a muted, looping YouTube video as a full-cover section background. Canvas uses a YTPlayer integration that reads the video URL and playback options from data attributes, then sizes the player to fill its containment element.
Core Markup
Add a .yt-bg-player element (with customjs when you want the theme to initialise it) and point data-video at any YouTube URL:
<div class="video-wrap">
<div class="yt-bg-player customjs"
data-quality="hd1080"
data-start="15"
data-stop="45"
data-video="https://youtu.be/LXb3EKWsInQ"></div>
<div class="video-overlay" style="background: rgba(0,0,0,0.4);"></div>
</div>Key Attributes
data-video: the YouTube URL (required). Acceptsyoutu.be/IDor full watch URLs.data-mute:true(default) orfalse. Autoplay requires muted.data-ratio: aspect ratio. Default:16/9.data-quality: playback quality such ashd720(default) orhd1080.data-opacity: player opacity, 0 to 1. Default:1.data-container: containment selector. Default:parent(the plugin auto-assigns an id to the parent).data-loop:true(default) orfalse.data-volume: volume 0 to 100. Default:50.data-start: start time in seconds. Default:0.data-stop: stop time in seconds. Default:0(play to end).data-autoplay:true(default) orfalse.data-controls: show player controls,falseby default.data-optimize: optimise display sizing,trueby default.data-coverimage: a fallback cover image URL.data-pauseonblur: pause when the tab loses focus,trueby default.data-playifvisible: only play while visible,falseby default.
Trimmed Loop Example
Loop just a segment of a longer video by combining data-start and data-stop:
<div class="yt-bg-player customjs"
data-quality="hd1080"
data-start="19"
data-volume="80"
data-stop="52"
data-video="https://youtu.be/G5eaRMifvPQ"></div>In a Slider
YouTube backgrounds work inside Canvas swiper slides. The slider plays the active slide's YouTube player automatically:
<div class="swiper-slide dark">
<div class="video-wrap">
<div class="yt-bg-player customjs" data-quality="hd1080"
data-start="15" data-stop="45"
data-video="https://youtu.be/LXb3EKWsInQ"></div>
</div>
</div>Tips
- Always add a
.video-overlaytint so overlaid text stays readable. - Use
data-startanddata-stopto loop the most visually interesting segment. - Leave
data-mute="true"(the default) so autoplay is not blocked by browsers. - Set
data-coverimagefor a smooth fallback while the YouTube player initialises.
Usage
<div class="section yt-bg-player nomargin dark" data-quality="hd1080" data-start="20" data-stop="40" data-video="http://youtu.be/A3PDXmYoF5U" style="height: 600px;">
<div class="container clearfix">
...
</div>
</div>Settings
| Setting | Description |
|---|---|
data-video | The Youtube Video URL, Short URL available from the Youtube Share Panel or the Video ID. Example: https://youtu.be/A3PDXmYoF5U |
data-mute | Mutes the Audio on the Youtube Video Example: true |
data-ratio | Aspect Ratio of the Youtube Video |
data-quality | Quality of the Youtube Video Example: hd1080 |
data-opacity | Opacity of the Youtube Video Example: 0.5 |
data-container | CSS selector of the DOM element where you want the Youtube Video background, if not specified it takes the "self" Example: body |
data-optimize | Setting this Option will fit the Youtube Video size into the window size optimizing the view. |
data-loop | Loops the Youtube Video |
data-volume | Sets the Volume of the Youtube Video Example: 60 |
data-start | Set the seconds the video should start from. Example: Setting data-start="20" will start the Video from 20 Seconds. |
data-stop | Set the seconds the video should stop at. Example: Setting data-stop="40" will start the Video at 40 Seconds. |
data-autoplay | AutoPlays the Youtube Video |
data-fullscreen | Activate the new HTML5 full screen behavior. |
Was this page helpful?
