Full Screen Video Background with Text Overlay

Full Screen Video Background with Text Overlay
Code Snippet:Full Screen Video with Text Overlay
Author: Lisa Catalano
Published: March 3, 2024
Last Updated: March 4, 2024
Downloads: 908
License: MIT
Edit Code online: View on CodePen
Read More

This code snippet helps you to create a full-screen video background with text overlay. It positions a video element covering the entire viewport with text overlaid on it. This is useful for showcasing videos as backgrounds with accompanying text. The code utilizes CSS for layout and positioning, ensuring the video covers the entire screen regardless of size.

You can use this code on websites to create captivating landing pages or homepage backgrounds. It helps grab attention with dynamic video backdrops while conveying essential text information.

How to Create Full-Screen Video Background With Text Overlay

1. First of all, load the Google Fonts by adding the following CDN links into the head tag of your HTML document. (Optional)

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@400;900&display=swap" rel="stylesheet">

2. Create the structure for your header using the <header> tag. Inside it, add a <video> tag with the src attribute pointing to your video file. Include a <div> for your header text and a separate <div> for descriptions or additional text. Modify the text in the description <div> to suit your message.

<header class="video-header">

  <video src="https://drive.google.com/uc?id=1QmPm1EdHE0yLepVKu8FqqpPxmNKSxwnC" autoplay loop playsinline muted></video>

  <div class="header-text">
    <h1>
      Exploring
      <span>The Sea</span>
    </h1>
  </div>
  <div class="description">
    <p>This is an example of a full screen video being shown as a background at any screen size. 
      This is accomplished with giving video absolute positioning, full viewport width and height, and using 'object-fit: cover;'
    </p>
    <p class="credit">Video credit: Taryn Elliot on <a href="https://www.pexels.com/video/colorful-fish-swimming-among-seaweed-5548030/">pexels.com.</a></p>
  </div>
</header>

3. Style the video background section using the following CSS styles. You can customize the CSS code according to your needs.

html, body {
  font-family: 'Raleway', sans-serif;
  background-color: teal;
}

video {
  width: 100dvw;
  min-height: 100dvh;
  position: absolute;
  top: 0;
  left: 0;
  object-fit: cover; 
}
.header-text {
  position: absolute;
  color: white;
  display: flex; 
  flex-direction: column;
  justify-content: center;
  text-align: center;
  transform: translateY(-5rem);
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;  
}
.header-text h1 {
  font-weight: 400;
  font-size: 1.75rem;
  text-transform: uppercase;
  line-height: 1;
}
.header-text span {
  display: block;
  font-weight: 900;
  font-size: 6rem;
}
.description {
  position: absolute;
  bottom: 0; 
  left: 0;
  right: 0;
  margin: auto;
  color: white;
  background-color: hsl(181deg 50% 20% / 70%);
  padding: 2rem; 
}
.description p {
  max-width: 40rem;
  margin-inline: auto;
  line-height: 1.6;
}
.credit {
  font-size: .75rem;
}
.credit a {
  color: white; 
  text-underline-offset: 2px;
}

That’s all! hopefully, you have successfully created a Full-Screen Video Background using HTML and CSS. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X