I have this Youtube video as the background of my site. It works exactly as intended in Opera, Brave, desktop Chrome, etc. But I have two issues:
- The video doesn't play automatically in Safari or Chrome on iOS, and the Youtube play button remains visible in the middle of the video (haven't tested on Android yet).
- Sometimes the video doesn't load upon the first visit to the page when I view it on my actual web domain instead of with the live server. It then works after a refresh.
This is the div in the body of my page with the video:
<div class="video-container">
<iframe src="https://www.youtube.com/embed/tSbwuwQqO3A?controls=0&autoplay=1&mute=1&playsinline=1&playlist=tSbwuwQqO3A&loop=1"></iframe>
</div>
and here is the CSS :
.video-container {
width: 100vw;
height: 100vh;
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -99;
}
iframe {
position: absolute;
top: 50%;
left: 50%;
width: 100vw;
height: 100vh;
transform: translate(-50%, -50%);
pointer-events: none;
}
I tried hosting the video locally in the project folder using a HTML video tag with the source set to the .mp4 file. I tried putting autoplay, loop, muted, playsinline and allowfullscreen inside of the tag, but the video wouldn't display full screen the same way as the Youtube embed does, which is the way I need it to.