Skip to content

Hero with Video Background

Tailwind CSS hero section with a muted looping background video, gradient overlay, call to action buttons and an accessible pause button.

Also known as: video background hero, fullscreen video header, looping background video, hero banner with video

Hero with Video Background live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A full-width hero section with a muted, looping background video, built with Tailwind CSS and a small vanilla JavaScript controller. A green gradient overlay keeps the headline readable, two call to action buttons sit below the copy, and a round button lets visitors pause the motion. It works well for travel brands, outdoor gear, events, hotels and product launches.

How it works

The root is section.hvb-hero, a flex column with min-h-[640px] and isolate. The video.hvb-video fills it with object-cover and carries autoplay muted loop playsinline, which is the combination mobile browsers require for inline autoplay. Its poster attribute shows an Unsplash waterfall photo until the first frame is ready, and it is aria-hidden because it is purely decorative. Above it, .hvb-overlay paints two gradients defined in style.css: a horizontal tint from the --hvb-tint color and a dark fade at the bottom behind the stats.

The content area contains a status pill with a pulsing .hvb-dot, the h1, a paragraph and two links styled as buttons. The bottom strip holds a dl with three figures and the .hvb-toggle button.

On DOMContentLoaded the script initializes every .hvb-hero. Clicking .hvb-toggle plays or pauses the video; the play and pause events swap the .hvb-icon-pause and .hvb-icon-play icons and update the button's aria-label. If autoplay is blocked, the rejected play() promise leaves the poster visible with a play button, and if the source fails to load, the button is hidden.

Customization

  • The source src inside .hvb-video: point it to your own MP4 file (keep it short, compressed and around 720p) and add a WebM source above it if you have one.
  • The poster attribute on .hvb-video: use a still frame from your own video so the first paint matches.
  • --hvb-tint in .hvb-overlay: an RGB triplet such as 30 27 75 turns the green overlay into deep indigo.
  • The alpha values 0.85, 0.45 and 0.15 in .hvb-overlay: raise them for busier footage, lower them for calm footage.
  • min-h-[640px] on .hvb-hero: use min-h-screen for a hero that fills the first screen.
  • bg-lime-300 on the primary button and logo: switch lime to another accent color.
  • Remove the .hvb-dot animation in style.css for a fully static pill.

Use cases

  • Travel brands: a muted looping clip behind the headline sets the mood for a destination
  • Outdoor gear shops: a green gradient overlay keeps text readable over busy footage
  • Hotels and resorts: two call to action buttons sit over the video, with a pause button for guests who prefer less motion
  • Events and product launches: a poster image shows instantly while the video loads, with stats displayed at the bottom

Accessibility

Motion that plays automatically for more than five seconds needs a way to stop it, so .hvb-toggle is always reachable by keyboard and announces "Pause background video" or "Play background video". When prefers-reduced-motion: reduce is set, the script removes autoplay and pauses the video, and the pulsing dot stops. The video is muted, hidden from assistive technology and removed from the tab order. The overlay keeps white text well above a 4.5:1 contrast ratio, and all links show a visible lime focus outline.

Usage notes

The demo video is a free Mixkit clip and the poster is from Unsplash; replace both with your own media and host the video yourself. Without JavaScript the video still autoplays and loops.

Hero with Video Background at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile, dark design
Category
Hero Sections
License
Free for personal and commercial use

Questions about this template

Can I use the Hero with Video Background code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Hero with Video Background – free Tailwind CSS hero section template
Hero with Video Background · free Tailwind CSS hero section template

More Hero Sections

Split Hero with Diagonal Photo Clip – free Pure CSS hero section template

Split Hero with Diagonal Photo Clip

Pure CSS split hero with headline, buttons and stats beside a full-height photo cut on a diagonal with clip-path, plus an accent stripe and rating badge.

Hero with Rotating Words – free Pure CSS hero section template

Hero with Rotating Words

Dark hero section whose headline cycles through words with a slide-and-fade animation, a pause button and decorative stat cards.

Split Hero with App Screenshot – free Tailwind CSS hero section template

Split Hero with App Screenshot

Dark Tailwind CSS split hero with gradient headline, two CTA buttons and an animated mock app dashboard built entirely from divs.

Dental Clinic Hero with Appointment Button – free WordPress hero section template

Dental Clinic Hero with Appointment Button

A dental clinic hero section with a booking button, a call button, three patient trust points and a rounded treatment room photo, built from core Gutenberg blocks.

Hero with Search Bar – free Bootstrap 6 hero section template

Hero with Search Bar

Bootstrap 6 directory hero on a photo background with a large pill search bar, a searchable area Combobox, popular search chips and category tiles.

Hero with Background Video Overlay – free Bootstrap 6 hero section template

Hero with Background Video Overlay

Full-width Bootstrap 6 hero with a muted background video or slow-zoom poster photo, dark gradient overlay, headline, two buttons, stats and a pause control.