IN A WORLD of responsive and fluid layouts on the web, ONE MEDIA TYPE stands in the way of perfect harmony: video. There are lots of ways in which video can be displayed on your site. You might be self-hosting the video and presenting it via the HTML5 tag. You might be using YouTube, Vimeo, or some other video provider that provides
code to display videos. Let’s cover how to make them all fluid width while maintaining an appropriate height based on their aspect ratio.
In each of these video-embedding scenarios, it is very common for a static width
and height
to be declared.
Guess what? Declaring static widths isn’t a good idea in fluid width environments. What if the parent container for that video shrinks narrower than the declared 400px
? It will bust out and probably look ridiculous and embarrassing.

So can’t we just do this?
Well, yep, you can! If you are using standard HTML5 video, that will make the video fit the width of the container. It’s important that you remove the height
declaration when you do this so that the aspect ratio of the video is maintained as it grows and shrinks, lest you get awkward “bars” to fill the empty space (unlike images, the actual video maintains it’s aspect ratio regardless of the size of the element).
You can get there via CSS (and not worry about what’s declared in the HTML) like this:
video {
/* override other styles to make responsive */
width: 100% !important;
height: auto !important;
}
Video (YouTube, Vimeo, etc.)
Our little trick from above isn’t going to help us when dealing with video that is delivered via . Forcing the width to 100% is effective, but when we set
height: auto
, we end up with a static height of 150px1, which is far too squat for most video and makes for more R&E (Ridiculous and Embarrassing).
Fortunately, there are a couple of possible solutions here. One of them was pioneered by Thierry Koblentz and presented on A List Apart in 2009: Creating Intrinsic Ratios for Video. With this technique, you wrap the video in another element which has an intrinsic aspect ratio, then absolute position the video within that. That gives us fluid width with a reasonable height we can count on.
.videoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
}
.videoWrapper iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
There is a clever adaptation of this that allows you to adjust the aspect ratio right from the HTML, like: