How to add YouTube video as background using HTML

Posted by admin on Wed, 01/17/2018 - 10:46

Code snippet to add YouTube video as a background for you HTML tag.

Here goes your HTML:

<div class="video-background">
    <div class="video-foreground">
      <iframe src="" frameborder="0" allowfullscreen></iframe>
<div id="vidtop-content">
<div class="vid-info">
	  <h1>YouTube background here!</h1>

Here is your CSS (most of that just for beauty):

* { box-sizing: border-box; }
.video-background {
  background: #000;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: -99;
.video-background iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
#vidtop-content {
	top: 0;
	color: #fff;
.vid-info { position: absolute; top: 0; right: 0; width: 33%; background: rgba(0,0,0,0.3); color: #fff; padding: 1rem; font-family: Avenir, Helvetica, sans-serif; }
.vid-info h1 { font-size: 2rem; font-weight: 700; margin-top: 0; line-height: 1.2; }
.vid-info a { display: block; color: #fff; text-decoration: none; background: rgba(0,0,0,0.5); transition: .6s background; border-bottom: none; margin: 1rem auto; text-align: center; }
@media (min-aspect-ratio: 16/9) {
  .video-foreground { height: 300%; top: -100%; }
@media (max-aspect-ratio: 16/9) {
  .video-foreground { width: 300%; left: -100%; }
@media all and (max-width: 600px) {
.vid-info { width: 50%; padding: .5rem; }
.vid-info h1 { margin-bottom: .2rem; }
@media all and (max-width: 500px) {
.vid-info .acronym { display: none; }

Hey! Don't miss a new cool stuff!


natalia (not verified)

Assuming you have an account and are logged in, point your curser on your username at the top right and in the drop down menu click My Videos. Once there look to the left of the page and you'll see a button that says NEW and point to it and you'll see a link pop up that says VIDEO UPLOAD which will bring you to the video upload page. help with assignment

Eden Carter (not verified)

Thanx for sharing such useful post keep it up :) Case Study Help

Alison Andrew (not verified)

I’m really impressed with your article, such great & usefull knowledge you mentioned here Do My Programming Homework

David Paul (not verified)

Pretty helpful material, much thanks for this article MYOB Assignment Help

Adam A. Storey (not verified)

by visiting this site I found cool stuff here keep it up. Accounting Assignment Help

Michele (not verified)

Youtube video in the background is not a good idea for your website, in my opinion. Mosto f the people who come to your essayvikings review site will just keep looking at the video in the background, and not the content on your site.

Add new comment