How to Make a Video Embed Responsive
17 Sep 2021
Quick summary:
You will need to wrap your iframe with a <div>
element that has the class embed-container
.
<div class="embed-container">
<iframe src="https://www.youtube.com/embed/gAYL5H46QnQ" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
Then add the following CSS to make it responsive:
.embed-container {
position: relative;
display: block;
width: 100%;
overflow: hidden;
height: 0;
padding-bottom: 56.25%;
border: 0;
}
.embed-container iframe {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
}
Your video should now look like this: