In this blog you will learn how to add a video background to your landing page to make it more gorgeous.

Add a video background to your landing page to make it more gorgeous

In this blog you will learn how to add a video background to your landing page to make it more gorgeous.

Preview:

Requirements:

  • Basic HTML & CSS knowledge
  • Basic Javascript(Optional. only required for the navigation toggle effect)

I have already created a video about it on my youtube channel. Check that out for more details.

If you like this video, please like share, and Subscribe to my channel.

source code: https://github.com/thatanjan/video-background-landing-page-yt

Starter code

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Taylor Swift</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="nav.css" />
<link rel="stylesheet" href="content.css" />
<link rel="stylesheet" href="responsive.css" />
</head>
<body>
This is body
<script src="index.js"></script>
</body>
</html>

Let's add the video and overlay to html.

<section class="video_container">
<video src="./media/background.mp4" autoplay loop muted></video>
<div class="overlay"></div>
</section>

Result: video with no style - Add video background to your landing page to make it more gorgeous by cules coding

Explanation:

  • A video container to contain the video and overlay.
  • Video will be started automatically with a loop. It will also be muted.

Css reset

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
max-width: 100vw;
overflow-x: hidden;
}

Explanation:

  • The entire webpage should not be bigger than the screen width.
  • Webpage will not have any horizontal scrolling.

Let's style the video:

.video_container {
min-height: 100vh;
max-height: 100vh;
overflow: hidden;
position: relative;
}
.video_container video {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}

Result: video styled but no overlay - Add video background to your landing page to make it more gorgeous by Cules Coding

Explanation:

  • The video container is taking the full width of the screen without any overflow. It is also positioned as relative.
  • Actual video is positioned absolute and aligned with the container. It is also taking the full height and width.

If you have confusion with Css position then you can watch this video.

  • To make the video fit, we need to use object-fit to cover.
  • If the user adjusts screen width, the user will always see the center of the video because of object-position: center;.

Let's style the overlay.

:root {
--primary-red: #70000e;
}
.overlay {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: var(--primary-red);
mix-blend-mode: soft-light;
}

Result: with overlay

Explanation:

  • Overlay element is aligned with the container using position absolute.
  • The background color is stored inside a variable. If you don't know about css variable, then you can check out this blog
  • Overlay has been blended with the background using a blend mode. We need to use mix-blend-mode property to do so. I will use soft-light as value. You can learn about mix-blend-mode from here

And that's how you add a video background to a landing page to make it more gorgeous. If you want to learn how the rest of the project was made please watch the video.

source code: https://github.com/thatanjan/video-background-landing-page-yt

Final result:

Shameless Plug

Want to create your own blog? Well, I am creating a video series where you will learn about how to create a JAMstack blog with Nextjs and Chakra-UI.

Lessons

Demo

You can demo the website from here

Features

  • Static Blog pages will make the website load faster.
  • Blogs will have code blocks with syntax highlighting and many embed components like youtube videos, GitHub gist, Tweets, and so many other things.
  • Autocomplete search feature for the blog posts.
  • Real-time view counter and so on.

Please like and subscribe to Cules Coding. It motivates me to create more content like this.

That's it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.

By the way, I am looking for a new opportunity in a company where I can provide great value with my skills. If you are a recruiter, looking for someone skilled in full-stack web development and passionate about revolutionizing the world, feel free to contact me. Also, I am open to talking about any freelance project. I am available on Upwork

Contacts

Blogs you might want to read:

Videos might you might want to watch:

Previous Post5 easy ways to center elements in CSS
Next PostEverything you need to know about css variables