Making landing page with background video
Tags: landingpage, backgroundvideo, responsiveiframe, youtubeembedded
Published: 2017-08-20 18:06:17

---
title: Making landing page with background video
published: true
description: Responsive and interactive landing page with underlying background video that plays on its own.
tags: Landing page, Background video, Responsive iframe, youtube embedded
---
<p data-height="265" data-theme-id="light" data-slug-hash="oeEVpK" data-default-tab="css,result" data-user="cfjr" data-embed-version="2" data-pen-title="A landing page with background video" class="codepen">See the Pen <a href="https://codepen.io/cfjr/pen/oeEVpK/">A landing page with background video</a> by Rounak Polley (<a href="https://codepen.io/cfjr">@cfjr</a>) on <a href="https://codepen.io">CodePen</a>.</p>
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
![Preview of the Landing Page](https://thepracticaldev.s3.amazonaws.com/i/octs96e108zo66tqs9k6.PNG)
This pen I have created only to showcase how to effectively embedded youtube videos as backgrounds. Heads up ! while we can use any video for experimental purposes for actual webpages always use videos with copyrights.

Lucky for me I used a video from my own youtube channel (<a href="https://www.youtube.com/channel/UCsjUxvNRuHkExvenByLVZ4Q">My channel</a>).

A landing page is the first thing the `user` lands on when visiting a website which makes is extremely important to leave a positive impression at first sight. Perhaps you want to showcase your brand or products or add a content relating to your website.
There are many ways of creating it but I think that creating one with underlying video is more challenging than other ones.

Here's what I found out...

If we just copy and paste the embedded code and set the `<iframe>` to take up the entire screen we are going to end up with lots of black space around the video which adjusts itself as we resize the browser window obviously nobody wants that! (not specially on a landing page). 
So, I tried another way I tried adding the background as an *animated gif* (compromising on the sound & I haven't seen landing pages with audio actually but I wanted audio as well).
Alas, I couldn't get any online resource to create a gif of longer than a minute and even my photoshop got upset in converting a 2min 32sec video into gif.
I tried some other things like styling the `<video>` element created within the `<iframe>` until I realized that I needed to make my embedded iframe responsive.
But, it too breaks down at extremely narrow browser size revealing white background underneath so I added a fixed positioned bottom centred gradient as background.
One thing that beats me is that I can't get the youtube video to loop (which user will probably find-out if he/she stays on the page for long enough) I did what the official sources said <a href="https://developers.google.com/youtube/player_parameters">YouTube Embedded Players and Player Parameters </a> (other sources give same info.) which is `loop=1`.

Further more colour or gradient overlays can be added on top of the background video like I added a curtain for framing.
I also added some simple text (with text shadow to improve readability) on the page with **Log in** & **Sign up** buttons with complimentary button styles.
And adding the usual Bootstrap classes to the required foreground components wraps up the thing.

And, as usual for complete code ...
<p data-height="265" data-theme-id="light" data-slug-hash="oeEVpK" data-default-tab="css,result" data-user="cfjr" data-embed-version="2" data-pen-title="A landing page with background video" class="codepen">See the Pen <a href="https://codepen.io/cfjr/pen/oeEVpK/">A landing page with background video</a> by Rounak Polley (<a href="https://codepen.io/cfjr">@cfjr</a>) on <a href="https://codepen.io">CodePen</a>.</p>
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>