RovelaRovela
Back to the blog

By El Ghali Bennis · Published

How to Add Video Background to Website Homepage

Add a homepage hero video without wrecking page speed. Exact HTML, file size targets, mobile fallbacks and accessibility fixes for online stores.

How to Add Video Background to Website Homepage

To add a video background to your website homepage, place a short, compressed MP4 or WebM inside a video tag with the autoplay, muted, loop and playsinline attributes, add a poster image, and layer your headline over it with CSS. Keep the file under 3 MB, the clip under 10 seconds, and serve a static image on mobile.

Store owner reviewing a looping homepage hero video on a laptop in a bright studio with product samples on the desk

That's the short version. The long version matters, because a homepage hero video is one of the easiest ways to make a store feel premium and one of the easiest ways to tank your load time. This guide covers the exact code, the file size and length targets, the mobile fallback, the accessibility rules, and the honest answer to whether video actually lifts conversion.

How do you add a video background to a website homepage?

You add a video background by embedding a self-hosted video file in a video element, setting it to autoplay muted on a loop, and positioning it behind your text. Four steps get you there: prepare the clip, add the markup, style it, and test it.

Step 1: Prepare the clip

Pick a clip with slow, simple motion: hands working with a product, fabric moving, steam rising, a pan across a workshop. Trim it to 6-10 seconds. Cut audio entirely, since browsers block autoplay with sound anyway. Export at 1920x1080 or even 1280x720, because a darkened background doesn't need 4K sharpness.

Step 2: Add the HTML

Here's the markup for an autoplay muted looping video website background:

<section class="hero">
  <video autoplay muted loop playsinline preload="metadata"
         poster="hero-poster.jpg">
    <source src="hero.webm" type="video/webm">
    <source src="hero.mp4" type="video/mp4">
  </video>
  <div class="hero-content">
    <h1>Your headline</h1>
    <a href="/shop">Shop now</a>
  </div>
</section>

Each attribute earns its place. muted is required for autoplay in Chrome, Safari and Firefox. playsinline stops iPhones from forcing fullscreen. poster shows an image while the video loads. preload="metadata" keeps the browser from grabbing the whole file before it needs to. The MDN Web Docs page on the HTML video element documents all of these attributes in detail.

Step 3: Style it with CSS

Make the section position: relative and about 70-90vh tall. Set the video to position: absolute, width: 100%, height: 100%, and object-fit: cover. Add a dark overlay of 30-50% opacity so white text stays readable. Put your content above it with a higher z-index.

Step 4: Test on real devices

Check Safari on an iPhone, Chrome on a mid-range Android, and a throttled 4G connection. Low-power mode on iOS can block autoplay, so your poster image has to look good on its own.

Developer testing a homepage video background on an iPhone and an Android phone side by side at a desk

Hero video vs hero image: which should you use?

Use a hero image if page speed and simplicity matter most, and a hero video if you sell something where motion shows the product, like fabric, food, or a process. A video costs far more bytes, so it has to earn its spot.

FactorHero imageHero video
Typical file size80-250 KB (WebP/AVIF)1.5-4 MB (compressed)
Load impactMinimalNoticeable on mobile
Emotional pullModerateHigh when motion fits the product
Accessibility effortLowNeeds pause control and reduced-motion handling
Best forFast-converting, price-led storesBrand-led, lifestyle, food, fashion, craft

My rule: if you can't say in one sentence what the motion shows that a photo can't, use the photo. A candle brand showing wax pouring has a reason. A generic clip of people laughing in an office doesn't.

The cleanest compromise is a video on desktop and a strong image on mobile. That gives you the brand moment where bandwidth is cheap and speed where it isn't.

Hero video file size, length and format targets

Aim for a hero video file size under 3 MB, a length of 6-10 seconds, and a resolution of 1280x720 to 1920x1080. Those numbers keep the hero playable on average mobile connections without pushing your page past a reasonable weight.

How long should a hero video be?

Between 6 and 10 seconds, looped seamlessly. Longer clips mean bigger files, and nobody watches a background video for 40 seconds. The trick is a loop that doesn't jolt: end on a frame that matches the first one, or use a slow pan that resets quietly.

Recommended export settings

  • Format: WebM (VP9 or AV1) first, MP4 (H.264) as fallback. WebM is often 20-40% smaller at the same quality.
  • Resolution: 1280x720 is plenty under an overlay.
  • Frame rate: 24 or 25 fps. Dropping from 60 fps cuts size sharply.
  • Bitrate: 1-2 Mbps for H.264 at 720p.
  • Audio: Strip it. It's dead weight.
  • Tools: HandBrake or FFmpeg, both free.

A quick FFmpeg command that works for most clips: ffmpeg -i input.mov -an -vf scale=1280:-2 -r 24 -c:v libx264 -crf 28 -movflags +faststart hero.mp4. The faststart flag lets playback begin before the file fully downloads.

Videographer trimming a short product clip in an editing timeline on a monitor in a small studio

Video hero page speed: protect your Core Web Vitals

A video hero hurts page speed when it's the largest element and loads late, which inflates Largest Contentful Paint. Google's guidance on web.dev says a good LCP is 2.5 seconds or less, so your poster image and video loading strategy decide whether you pass.

Make the poster your LCP element

The browser treats the poster image as the content to paint first. Compress it as WebP or AVIF at around 100-150 KB, and preload it with a link rel="preload" as="image" tag. Then the video can load behind it without blocking anything visible.

Don't use YouTube or Vimeo embeds as backgrounds

An embedded iframe pulls in hundreds of kilobytes of third-party scripts and gives you little control over autoplay behavior. Self-host a small file, or use a video CDN that serves optimized renditions. You'll save more than you'd think.

Other speed habits that matter

  • Set preload="metadata" or none so the browser doesn't hog bandwidth.
  • Delay video loading until after the poster paints, using a small script that sets the source on load.
  • Serve one clip only. Two heroes means double the bytes.
  • Run PageSpeed Insights before and after, on mobile settings, and compare LCP honestly.

If you're running a store, this is where your stack matters. Every plugin that injects its own scripts competes with your hero for bandwidth. If you're already wrestling with a heavy app stack, our guide on ecommerce homepage design shows how to keep the above-the-fold area lean.

Website background video mobile fallback and accessibility

A good mobile fallback swaps the video for a static poster image on small screens or slow connections, and a good accessibility setup respects reduced-motion preferences and gives visitors a pause button. Both are small additions that prevent real problems.

Mobile fallback pattern

Mobile visitors often pay for data and run on weaker processors. The simplest approach is CSS: hide the video under about 768px wide and show the poster as a background image on the section. Or load the video source with JavaScript only when window.matchMedia("(min-width: 768px)") matches. Either way, the phone never downloads the clip.

Reduced motion background video accessibility

Some visitors get dizziness or nausea from moving backgrounds, and they tell their operating system so. Respect that with the prefers-reduced-motion media query: if it's set to reduce, pause the video and show the poster. The W3C's Web Content Accessibility Guidelines (WCAG 2.2) also require a mechanism to pause, stop or hide any motion that starts automatically and lasts more than five seconds. A small pause button in the corner satisfies that.

@media (prefers-reduced-motion: reduce) {
  .hero video { display: none; }
  .hero { background: url(hero-poster.jpg) center/cover; }
}

Contrast and readability

Text over moving footage fails contrast checks fast. Use a dark overlay, keep headlines large, and test the worst frame of your loop, not the best. Keep your call to action in a solid button, not floating text.

Designer checking text contrast on a homepage hero section on a large monitor beside a printed color swatch

Does video increase ecommerce conversion? Best practices and examples

Video can raise conversion, but a background video on its own is not proven to. The stronger evidence is for product videos on product pages, not decorative homepage loops. Treat the hero video as a brand and engagement tool, then test it against an image.

Wyzowl's annual video marketing survey regularly reports that most consumers say video helps them decide to buy, but that's about explanatory and product video, not ambient backgrounds. Don't assume a pretty loop pays for itself. Run an A/B test for at least two full weeks, tracking add-to-cart rate and bounce rate, not just time on page.

Ecommerce hero video best practices

  1. Show the product in use. Hands, textures, steam, pouring, stitching.
  2. Keep the headline and button obvious. The video is the backdrop, not the message.
  3. Use one clear call to action above the fold.
  4. Match the loop to your brand pace. A slow-living candle brand shouldn't have fast cuts.
  5. Test against a static hero. Keep whichever wins on revenue per visitor.

Hero section video examples worth studying

  • Food and drink brands: slow-motion pours and sizzles that make people hungry.
  • Apparel and swimwear: fabric moving on a model, which a still photo can't show.
  • Furniture and decor: a slow pan through a styled room.
  • Handmade goods: a maker's hands shaping the product, which builds trust.

For a video background for an online store specifically, pair the hero with social proof just below it. Our walkthrough on adding testimonials to your ecommerce homepage covers that, and these AI generated website examples show how different stores structure their first screen.

Adding a hero video without touching code

If you'd rather not hand-edit HTML and CSS, most store platforms offer a hero video section, but many hide it behind a premium theme or an app. On Shopify, for example, video backgrounds often depend on your theme or a paid add-on, which adds to the monthly app bill and another script to load.

With Rovela, you can describe the homepage you want in chat, including a looping hero video with a mobile image fallback, and the store is built on standard Next.js code you can download and own. That keeps the hero fast without an extra plugin. If you're still deciding on a platform, the guide to building an online store without coding is a good starting point.

Common mistakes to avoid

  • Uploading a raw 40 MB file. Always compress first.
  • Forgetting muted. Autoplay silently fails without it.
  • No poster image. Visitors see a black box while loading.
  • Ignoring mobile. A desktop-only test hides the real problem.
  • Using the video as the only message. If the clip fails, your headline and button must still carry the page.
  • Skipping the pause control. It's an accessibility gap and a WCAG failure.

Wrapping up: ship a hero video that earns its place

A homepage video background works when it's short, small, muted, and backed by a sharp poster image and a mobile fallback. Keep it under 3 MB and 10 seconds, respect reduced-motion settings, and test it against a static hero before you commit.

If you'd rather skip the code and the plugin juggling, Rovela builds a complete store from a conversation, with 100+ features included and a fast Next.js architecture. You can see how it works on the Rovela homepage or check the pricing page for the flat monthly cost.

External references worth bookmarking: MDN's video element documentation, web.dev for Core Web Vitals guidance, and the W3C WCAG overview.

Your dream store is one sentence away.