Using CSS to Embed a Video in a Website

Using CSS to Embed a Video in a Website

HTML5 video embedding involves a predefined box wherein a video would sit. Some developers have begun using a more creative approach, embedding the video which blends with backgrounds or other CSS styling. Most developers would attempt to define this embedding quality while defining the canvas with HTML to blend in with the background color, but there's a tiny issue that some of you have probably noticed: The colors never quite match up like they should.

Why, you ask, does this happen? More importantly, how do you circumvent this?

The magic of CSS can step in and do what HTML isn't so efficient for. The CSS canvas element can circumvent the mismatching colors by perfectly blending them together as intended. What ordinarily stops this from panning out with HTML is the limited color range that's tapped by users' GPUs in a page, which is difficult to define without the flexibility of CSS. The result is that while some users' rigs will render everything normally, others will show a distinct difference between the video and the backdrop.

It's important to note that this "bug" has nothing to do with HTML or CSS; the CSS "canvas" element only works because it allows the developer to set support for specific color ranges as determined by a user's GPU. While some can hop on your web page and see everything in glorious HTML, others would have to see it rendered in CSS for the blending effect to work the way it should. We don't recommend this dualistic approach because, as always, simplicity is an elegant key to a fluid and functional website, but that decision is up to you.

There's a tutorial for canvas embedding, which actually renders the video directly into the canvas itself as a unified page element instead of superimposing the video on top of the backdrop. This is pretty smart and should solve a handful of issues for some of the artists out there whose canvas is none other than the face of the Internet. Enjoy! For more information click here