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
sourcesrcinside.hvb-video: point it to your own MP4 file (keep it short, compressed and around 720p) and add a WebMsourceabove it if you have one. - The
posterattribute on.hvb-video: use a still frame from your own video so the first paint matches. --hvb-tintin.hvb-overlay: an RGB triplet such as30 27 75turns the green overlay into deep indigo.- The alpha values
0.85,0.45and0.15in.hvb-overlay: raise them for busier footage, lower them for calm footage. min-h-[640px]on.hvb-hero: usemin-h-screenfor a hero that fills the first screen.bg-lime-300on the primary button and logo: switchlimeto another accent color.- Remove the
.hvb-dotanimation instyle.cssfor 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.