Youtube video iframe hack responsive

Category: | Tag:

How to make Youtube video iframe responsive

Youtube iframe code has fixed width and height, and this make responsive layout a bit problem. To solve this problem use below HTML code and CSS

HTML

<div class="videoWrapper">
<iframe width="560" height="315" src="[YouTube Video URL]?rel=0" frameborder="0" allowfullscreen></iframe>
</div>

CSS

.videoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
.videoWrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

Youtube video ‘no related video’ at the end

Add ?rel=0 after Youtube url

<iframe width=”640″ height=”360″ src=”[YouTube Video URL]?rel=0&autoplay=1″ frameborder=”0″ allowfullscreen></iframe>

Youtube video auto play

<iframe width="560" height="315" src="https://www.youtube.com/embed/GCStS6_wQ2U?autoplay=1&amp;mute=1" allowfullscreen></iframe>

Use Plugin

Another option is to use this Plugin.

Copyright © 2024 Siam Naulak.
magnifiercrossmenu