<section class="wrap">
<div class="video-bg">
<iframe src="https://www.youtube.com/embed/Xe62J2ca87c?autoplay=1&mute=1&playsinline=1&loop=1&playlist=Xe62J2ca87c&controls=0&disablekb=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="content">
<div class="container">
<h1 class="title">
YouTube Embed Background without JS
</h1>
</div>
</div>
</section>
html, body {
margin: 0;
padding: 0;
}
.wrap {
position: relative;
height: 100vh;
}
.video-bg {
position: relative;
height: 100%;
background: #000;
overflow: hidden;
}
.video-bg::after {
content: '';
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .3);
background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.4' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E");
}
.video-bg iframe {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100vw;
height: 60vw;
}
.content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
color: #fff;
}
.container {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
}
.title {
text-align: center;
font-size: 2.5vw;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.