-
Hajipur, Bihar, 844101
Responsive videos automatically scale to fit different screen sizes and maintain their aspect ratio (usually 16:9) without being cut off or distorted.
By default, <video>
or <iframe>
elements (like YouTube) use fixed width/height, which may overflow or not adjust properly on smaller screens.
✅ Keeps layout clean across devices
✅ Avoids horizontal scroll on mobile
✅ Maintains correct aspect ratio
✅ Improves user experience on all screen sizes
✅ Works well with embedded videos (e.g. YouTube, Vimeo)
aspect-ratio
)<div class="video-wrapper">
<iframe src="https://www.youtube.com/embed/ScMzIvxBSi4" allowfullscreen></iframe>
</div>
.video-wrapper {
aspect-ratio: 16 / 9;
width: 100%;
}
.video-wrapper iframe {
width: 100%;
height: 100%;
border: none;
}
✅ Benefit: Clean, minimal code with native CSS support (modern browsers).
padding-bottom
Hack (Traditional Method)<div class="video-container">
<iframe src="https://www.youtube.com/embed/ScMzIvxBSi4" allowfullscreen></iframe>
</div>
.video-container {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
overflow: hidden;
}
.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
✅ Benefit: Works in all modern browsers including older ones.
<video>
Tag Responsive<video controls class="responsive-video">
<source src="movie.mp4" type="video/mp4">
</video>
.responsive-video {
width: 100%;
height: auto;
max-width: 800px;
display: block;
margin: auto;
}
✅ Write HTML/CSS for the following:
Q1. Create a responsive YouTube embed using the aspect-ratio
property.
Q2. Use the padding-bottom
trick to make an iframe responsive.
Q3. Make an HTML5 <video>
scale with the screen width.
Q4. Embed a Vimeo video that maintains 16:9 ratio.
Q5. Make a video player center-aligned and responsive.
Q6. Apply media queries to adjust video margins on mobile.
Q7. Use max-width
to restrict video size on large screens.
Q8. Add responsive subtitles using <track>
in HTML5 video.
Q9. Create a responsive layout with 2 videos side-by-side on desktop and stacked on mobile.
Q10. Add responsive background video with object-fit: cover
.
Q1: What is the default problem with embedding a video via iframe on mobile?
Q2: What does aspect-ratio: 16/9; do?
Q3: Which element is commonly used to wrap responsive videos?
Q4: Which CSS trick is used to maintain video aspect ratio in older browsers?
Q5: How do you make a <video> tag scale responsively?
Q6: What is the purpose of iframe { width: 100%; height: 100%; }?
Q7: What is the full width + 16:9 padding-bottom percentage?
Q8: Which property is NOT used in responsive videos?
Q9: How do you make two videos responsive and stack on mobile?
Q10: Which CSS property helps avoid overflow in video containers?