How to add Full Screen Background Video using Tailwind CSS ?
Tailwind CSS is a CSS framework that helps in building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Tailwind CSS creates small utilities with a defined set of options enabling easy integration of existing classes directly into the HTML code.
In this article, we will see how to add a full-screen background video in Tailwind CSS. Using some tailwind classes, we can make a full-screen video background that covers the entire browser screen.
- relative: It sets the header element relative and makes the video absolute to position it.
- flex: It adds a display flex so we can align the text block inside.
- items-center: It aligns the text block vertically.
- justify-center: It aligns the text block horizontally.
- h-screen: It adds a 100vh height, so the video is scaled to 100% of the viewport height.
- mb-12: It adds a big margin-bottom with this (3rem).
- overflow-hidden: It makes the video bigger than the header so we do not want to show the overflow.
- absolute: It makes the video absolute positioned element.
- z-10: It gives the video a lower z-index than our text block to keep it in the background.
- w-auto: The width can be “auto” so that it will adjust accordingly.
- min-w-full: It makes the min-width 100%.
- min-h-full: It makes the min-height 100%.
- max-w-none: It unsets the default max-width.
Steps for adding full-screen background video in HTML.
Step 2: Add the <video> tag.
Step 3: Define classes to add video in the full-screen background.
className=”absolute z-10 w-auto min-w-full min-h-full max-w-none”></video>
Example 1: Below example demonstrates how to add a full-screen background video using Tailwind CSS.
In the given example, we have used an <video> element to add a video source in the background and the video is set to full screen using the tailwind CSS classes as explained above.
Example 2: Below example demonstrates a full-screen background video having a button on its top using Tailwind CSS.
In the given example, we have used an HTML header tag and also have an HTML <div> that will hold a block so that it sits on top of the video. Along with this, a <video> tag is used to hold a video or multiple sources.