The Complete Guide to Background Videos That Don't Ruin Your Website
Background videos can make or break your landing page. Here's how to get the cinematic look without destroying your page speed, mobile experience, or Core Web Vitals.
A well-executed background video instantly communicates what words and static images can't. A poorly executed one makes your site feel slow, drains mobile batteries, and sends your bounce rate through the roof.
The difference comes down to a handful of technical decisions.
The golden rules of background video
Before diving into implementation, here are the non-negotiable rules:
- Keep it under 3MB. For a 15-30 second loop, this is achievable with proper compression. Under 2MB is even better.
- Strip the audio. Background videos should always be muted. Removing the audio track entirely saves file size and avoids browser autoplay restrictions.
- Keep it short. 10-20 seconds is the sweet spot. Longer videos mean larger files with no real benefit; users rarely watch background videos for more than a few seconds.
- Use subtle motion. Slow pans, soft focus, and gentle movement. Fast action or complex scenes require higher bitrates to look good, which means larger files.
The ideal compression settings
Here's what to aim for when compressing a background video:
| Setting | Recommended value | Why |
|---|---|---|
| Codec | H.264 | Universal browser support |
| CRF | 28-32 | Background videos are decorative; slight quality loss is invisible behind overlays |
| Resolution | 1280x720 | 720p is sufficient for backgrounds. 1080p only if the video is truly full-bleed on desktop. |
| Frame rate | 24fps | Cinematic feel, smaller files. No need for 30 or 60fps. |
| Audio | Strip entirely | Not just muted; removed from the file entirely |
| Duration | 10-20 seconds | Seamless loop if possible |
| Target size | 1-3 MB | Fast load even on slower connections |
Notice the CRF is higher (lower quality) than you'd use for a content video. Background videos sit behind text overlays, color tints, or gradient masks. Nobody is examining the fine detail. A CRF of 28-32 looks perfectly fine in this context and dramatically reduces file size.
The HTML implementation
Here's a solid, production-ready background video setup:
<section class="relative h-screen overflow-hidden">
<!-- Video -->
<video
class="absolute inset-0 h-full w-full object-cover"
autoplay
muted
loop
playsinline
preload="auto"
poster="hero-poster.webp">
<source src="hero-bg.mp4" type="video/mp4">
</video>
<!-- Overlay -->
<div class="absolute inset-0 bg-black/50"></div>
<!-- Content -->
<div class="relative z-10 flex h-full items-center justify-center text-white">
<h1>Your headline here</h1>
</div>
</section>Key points:
object-covermakes the video fill the container like a background image, cropping as needed.playsinlineprevents iOS from going fullscreen.- The overlay (
bg-black/50) serves double duty: it makes text readable AND hides compression artifacts. A darker or blurred overlay means you can push compression even further. postergives users something to see instantly while the video loads.
The mobile problem
Background videos on mobile are controversial for good reasons:
- Data usage. Even a 2MB video adds up on metered connections.
- Battery drain. Video decode consumes more power than displaying a static image.
- Small screens. The cinematic impact is lost on a 6-inch display.
- Performance. Lower-end phones may stutter or lag.
Option 1: Replace with a static image on mobile
The most common approach. Show the video on desktop, show the poster image on mobile:
<video
class="hidden md:block absolute inset-0 h-full w-full object-cover"
autoplay muted loop playsinline
poster="hero-poster.webp">
<source src="hero-bg.mp4" type="video/mp4">
</video>
<!-- Mobile fallback -->
<img
src="hero-poster.webp"
alt=""
class="md:hidden absolute inset-0 h-full w-full object-cover">Option 2: Use a shorter, smaller video on mobile
If you really want video on mobile, serve a smaller version:
<video autoplay muted loop playsinline class="absolute inset-0 h-full w-full object-cover">
<source src="hero-bg-mobile.mp4" type="video/mp4"
media="(max-width: 767px)">
<source src="hero-bg.mp4" type="video/mp4">
</video>The mobile version should be 640x360 or 480p, CRF 30+, and under 1MB.
Option 3: Respect reduced motion preferences
Some users have vestibular disorders or simply prefer less motion. Always respect the prefers-reduced-motion media query:
@media (prefers-reduced-motion: reduce) {
video {
display: none;
}
}Creating a seamless loop
A jarring cut at the loop point ruins the effect. Here are two approaches:
1. Shoot for loops
Plan your footage with looping in mind. Static camera, consistent lighting, no beginning or end to the action. Think: clouds moving, water flowing, people walking through a space.
2. Cross-fade in editing
If your footage doesn't loop naturally, create a cross-fade:
- Duplicate the clip
- Overlap the end of the first with the beginning of the second by 1-2 seconds
- Apply a cross-dissolve transition
- Export the middle section
This creates a clip where the end blends smoothly into the beginning.
Preloading strategy
For above-the-fold background videos, you want the video to start as quickly as possible. Use preload="auto" and consider a preload link in the <head>:
<head>
<link rel="preload" as="video" href="hero-bg.mp4" type="video/mp4">
</head>Only do this for the hero video. Preloading multiple videos wastes bandwidth.
For background videos below the fold, use preload="none" and load them with Intersection Observer when they scroll into view.
Common mistakes to avoid
Mistake 1: Using 4K or 1080p when 720p is enough
Your background video sits behind an overlay. Nobody can tell the difference between 720p and 4K through a semi-transparent color wash. Use 720p and pocket the 60-75% file size savings.
Mistake 2: Forgetting movflags faststart
When encoding with FFmpeg, always include -movflags faststart. This moves the video metadata to the beginning of the file, allowing playback to start before the full download completes. Without it, the browser must download the entire file before it can play the first frame.
Mistake 3: Leaving audio in the file
Even if the <video> element has muted, the audio track is still in the file and still being downloaded. Strip it entirely during compression to save 10-20% file size.
Mistake 4: No poster image
Without a poster, users see a black rectangle until the video loads. Always provide a poster image (ideally a WebP under 50KB) for instant visual feedback.
Mistake 5: Autoplaying with sound
This will never work reliably. Browsers block autoplay with audio. Don't fight it. Background videos should always be muted, both in the HTML attribute and by stripping audio from the file itself.
Performance checklist
Before shipping a background video, verify:
- [ ] File size is under 3MB (ideally under 2MB)
- [ ] Audio track is stripped, not just muted
- [ ] Resolution is 720p or lower
- [ ] Frame rate is 24fps
- [ ] Poster image is set and loads instantly
- [ ]
playsinlineattribute is present for iOS - [ ] Mobile fallback is in place (static image or smaller video)
- [ ]
prefers-reduced-motionis respected - [ ] Video dimensions are set to prevent layout shift
- [ ]
movflags faststartwas used during encoding
Get these right and your background video will enhance your site instead of crippling it.
