44

How can you display HTML5 <video> as a full screen background to your website? Similar to this Flash site demo...

http://activeden.net/item/full-screen-video-background-template-v2/full_screen_preview/29617

David Thomas
  • 249,100
  • 51
  • 377
  • 410
Yammi
  • 465
  • 1
  • 4
  • 6
  • http://stackoverflow.com/questions/1055214/is-there-a-way-to-make-html5-video-fullscreen You can check in there – saturngod Oct 10 '10 at 10:15
  • I saw that post already, that seems to be more concerned with playing video outside the browser window at full screen, I'm looking for re-sizeable in-browser video. I thought there might be more out there on this although this link looks a bit more promising – Yammi Oct 10 '10 at 10:26
  • I'm not posting this as an answer, because I've only got empirical evidence, but testing in Chrome and Firefox (Ubuntu 10.04) suggests that this isn't possible. I am, however, fascinated to be proven wrong. +1 and starred, just in case. – David Thomas Oct 10 '10 at 10:28

3 Answers3

28

Use position:fixed on the video, set it to 100% width/height, and put a negative z-index on it so it appears behind everything.

If you look at VideoJS, the controls are just html elements sitting on top of the video, using z-index to make sure they're above.

HTML

<video id="video_background" src="video.mp4" autoplay>

(Add webm and ogg sources to support more browsers)

CSS

#video_background {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: -1000;
}

It'll work in most HTML5 browsers, but probably not iPhone/iPad, where the video needs to be activated, and doesn't like elements over it.

Volker E.
  • 5,911
  • 11
  • 47
  • 64
heff
  • 3,171
  • 1
  • 20
  • 21
7

I might be a bit late to answer this but this will be useful for new people looking for this answer.

The answers above are good, but to have a perfect video background you have to check at the aspect ratio as the video might cut or the canvas around get deformed when resizing the screen or using it on different screen sizes.

I got into this issue not long ago and I found the solution using media queries.

Here is a tutorial that I wrote on how to create a Fullscreen Video Background with only CSS

I will add the code here as well:

HTML:

<div class="videoBgWrapper">
    <video loop muted autoplay poster="img/videoframe.jpg" class="videoBg">
        <source src="videosfolder/video.webm" type="video/webm">
        <source src="videosfolder/video.mp4" type="video/mp4">
        <source src="videosfolder/video.ogv" type="video/ogg">
    </video>
</div>

CSS:

.videoBgWrapper {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    z-index: -100;
}
.videoBg{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

@media (min-aspect-ratio: 16/9) {
  .videoBg{
    width: 100%;
    height: auto;
  }
}
@media (max-aspect-ratio: 16/9) {
  .videoBg {
    width: auto;
    height: 100%;
  }
}

I hope you find it useful.

multimediaxp
  • 9,348
  • 13
  • 49
  • 80
  • 1
    This is a great answer to me, I do not know people down vote on this answer. The people who down vote it can you give some explanation why? – zt1983811 Aug 05 '16 at 13:41
5

Just a comment on this - I've used HTML5 video for a full-screen background and it works a treat - but make sure to use either Height:100% and width:auto or the other way around - to ensure you keep aspect ratio.

As for Ipads -you can (apparently) do this, by having a hidden and then forcing the click event to fire, and having the function of the click event kick off the Load/Play().

P.s - this shouldn't require any plugins and can be done with minimal JS - If you're targeting any mobile device (I would assume you might be..) staying away from any such framework is the way forward.

Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89