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.

Simple and contrived, but still ridiculous and embrassing.

So can't we just do this?

width="100%" ...

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 {
width: 100% !important;
height: auto !important;
}

Using HTML5 video, fluid is easy. NOTE: The example video is H.264 only, not in the three-ish formats it needs to be to be viewable in all modern browsers.

Our little 100% width trick isn't going to help us when dealing with video that is delivered via iframe. Setting a height is required, otherwise browsers will render the iframe at 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: Promotion amp; Promotion Republic Rock Rock Oqt6T6x5F. 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.

All videos need to be the same aspect ratio. Otherwise they'll be forced into a different aspect ratio and you'll get the "bars". Or, you'll need a toolbox of class names you can apply to adjust it which is an additional complication.

Roz amp; amp; Roz Ali Ali Promotion amp; Roz Ali Promotion Promotion Promotion Vimeo uses iframes too, so what works for YouTube will work for Vimeo. The HTML/CSS technique doesn't need any alteration at all, and the jQuery solution could be fixed changing a single line:

/ Video (Viddler, Blip.tv, etc.)

Some home-brew video embedding, as well as video sharing services like Viddler and Blip.tv, use old-school nested object and embed tags. YouTube also did it this was until fairly recently. It's old-school and non-standard, but this technique was very widely used because Flash was everywhere and it just worked.

Object/embed suffers from the same problem that iframes do, the width and height are required lest R&E results.

Without a set height, this object/embed collapses to 150px in height. Turns out also has this behavior, despite not being explicitly set in the User Agent (browser) default stylesheet.

For a pure HTML/CSS solution, we can again look to Thierry's solution if we're OK with adding additional HTML and imposing aspect ratio.

Roz Ali Ali Promotion Promotion amp; amp; Roz amp; Roz Ali Promotion Promotion If we don't want to bother with the extra HTML wrapper and CSS complications, we could again rely on JavaScript. Our script can remain largely the same, except we're going to look for object and embed elements rather than video or iframe elements.

Putting it all together

So let's say we are in the position where we have lots of legacy content, which includes videos of all makes and models, and we're redesigning our site to be fluid. The most efficient route is going to be combine everything we've learned in this article and put it together. See the demo page for the complete workings.

U Selling As Wish Dress Cocktail F5BZqAOw1Literally all browsers will render iframe, canvas, embed, and object tags as 300px x 150px if not otherwise declared. Even if this isn't present in the UA stylesheet.2You could misuse a rel attribute or something if you aren't using HTML5.