Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a header video only when motion supports the page’s message. The most reliable pattern is a short, muted, inline video behind readable foreground content, with a poster image, a static fallback, and a visible play or pause control. For users who prefer reduced motion, show the poster or require an intentional click.

This guide shows complete HTML and CSS, explains browser autoplay behavior, compares implementation patterns, and provides a testing and troubleshooting checklist.

What a website header video should do

A header (or hero) video is usually a decorative loop behind a headline and call to action. It should add atmosphere without carrying information that exists nowhere else. Keep the headline, supporting copy, buttons, product claims, and navigation in normal HTML so they remain available when the video does not load or play.

If the footage explains a product, contains speech, demonstrates a procedure, or communicates any essential detail, it is not merely a background. Provide an equivalent written explanation, captions, a transcript, and accessible playback controls. Do not put important meaning only in a layer marked aria-hidden="true".

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A robust decorative hero implementation

The following pattern uses the attributes commonly recommended for a decorative hero: autoplay, muted, loop, and playsinline. It supplies WebM and MP4 sources, a poster, a contrast scrim, and a real control for visitors who want to pause motion.

<section class="hero">
  <video class="hero__video"
         autoplay
         muted
         loop
         playsinline
         poster="/images/hero-poster.webp"
         aria-hidden="true">
    <source src="/video/hero.webm" type="video/webm">
    <source src="/video/hero.mp4" type="video/mp4">
  </video>
  <div class="hero__scrim" aria-hidden="true"></div>
  <div class="hero__content">
    <h1>Make the value clear in one line</h1>
    <p>Keep the message readable while the background supplies atmosphere.</p>
    <a class="hero__cta" href="/learn">Learn more</a>
  </div>
  <button class="hero__toggle" type="button" aria-pressed="false">
    Pause background video
  </button>
</section>

CSS for the layer, crop, and readable text

.hero {
  position: relative;
  min-height: 34rem;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: #17202a;
  color: #fff;
}

.hero__video,
.hero__scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hero__video {
  z-index: -2;
  object-fit: cover;
  object-position: center;
}

.hero__scrim {
  z-index: -1;
  background: rgba(0, 0, 0, .42);
}

.hero__content {
  width: min(42rem, calc(100% - 2rem));
  padding: 5rem 0;
  text-align: center;
}

.hero__content h1 { font-size: clamp(2rem, 6vw, 4.5rem); }
.hero__content p { font-size: clamp(1.05rem, 2vw, 1.35rem); }
.hero__cta,
.hero__toggle {
  display: inline-block;
  margin: .75rem .35rem 0;
  padding: .7rem 1rem;
  border: 2px solid #fff;
  border-radius: .35rem;
  color: #fff;
  background: rgba(0, 0, 0, .35);
}

@media (prefers-reduced-motion: reduce) {
  .hero__video { display: none; }
  .hero { background: url('/images/hero-poster.webp') center/cover no-repeat; }
}

Pause behavior

Autoplay is not guaranteed. Add a small script that lets keyboard and pointer users stop the loop, and change the label so the state is clear.

const video = document.querySelector('.hero__video');
const toggle = document.querySelector('.hero__toggle');

if (video && toggle) {
  toggle.addEventListener('click', () => {
    if (video.paused) {
      video.play().catch(() => {});
      toggle.textContent = 'Pause background video';
      toggle.setAttribute('aria-pressed', 'false');
    } else {
      video.pause();
      toggle.textContent = 'Play background video';
      toggle.setAttribute('aria-pressed', 'true');
    }
  });
}

if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
  video?.pause();
}

If JavaScript is disabled, the poster and normal HTML still provide a usable hero. If your design cannot offer a meaningful control, use the poster-only pattern instead of forcing motion.

Autoplay: what browsers allow

Modern browsers commonly block autoplay when a video has an audible track. Muted, inline playback is more likely to start, but it can still be stopped by browser policy, data-saving settings, low-power modes, user preferences, or platform-specific behavior. Treat autoplay as an enhancement, never as a dependency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Set muted and remove an unnecessary audio track from a permanently muted file.
  • Set playsinline so supported mobile browsers can play in the page rather than taking over the screen.
  • Keep the poster visible while the file loads and when playback is blocked.
  • Provide a visible, keyboard-focusable play or pause control when motion remains available.
  • Do not assume a browser’s autoplay setting is an accessibility solution; controls and fallbacks belong in your page.

If you are unsure whether autoplay is appropriate, do not autoplay. A still image usually communicates the same atmosphere with less risk and less work.

Respect reduced motion and visual sensitivity

Honor prefers-reduced-motion: reduce by replacing the moving background with the poster or a user-activated play button. Rapid flashes, abrupt cuts, and high-contrast loops can be especially difficult for people with photosensitive epilepsy or vestibular disorders. Keep transitions gentle, avoid strobing, and make the pause action easy to find.

A decorative video should be marked aria-hidden="true" only when all of its meaning is duplicated in nearby text. A feature video needs a descriptive accessible name, captions for speech, a transcript, and standard controls such as play, pause, seek, volume, and fullscreen.

Choose the right header pattern

Pattern Best use First-load cost Accessibility and fallback Mobile behavior
Static poster only Motion adds little or the page must be extremely light Lowest Simple, predictable, and safe Works everywhere
Muted decorative autoplay Short atmospheric loop behind a clear message Higher; can download immediately Needs poster, scrim, reduced-motion handling, and pause control Autoplay may be blocked; inline playback is more likely with playsinline
Click-to-play feature video Speech, instructions, demonstrations, or product detail Deferred until intent Use captions, transcript, accessible name, and full controls Explicit tap avoids many autoplay surprises
Hosted or streamed hero asset Delivery, encoding, analytics, or global distribution needs exceed a simple file Depends on provider and configuration Verify provider controls, poster behavior, privacy, and autoplay handling Test provider behavior on each target platform

Keep the header fast

Trim and encode for the job

  • Use a short, tightly framed clip with restrained motion.
  • Export a compressed WebM source and an MP4 fallback.
  • Remove audio when the hero is always muted; an audio track adds bytes without value.
  • Design the focal area for center cropping, because object-fit: cover will cut edges at some aspect ratios.

Delay work below the fold

An autoplaying video can begin downloading as soon as the page is parsed. For a hero that starts below the initial viewport, keep the poster as the immediate asset and use viewport-aware loading so the video is requested only when it approaches view. Do not use eager loading for every video on a long page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Protect layout stability and contrast

Give the hero a stable height or aspect ratio before the video arrives. This prevents content from jumping. A scrim, gradient, or carefully chosen text position keeps the copy readable across changing frames; test the brightest and darkest moments, not just the opening frame.

Implementation checklist

  1. Write the headline, supporting text, and call to action as ordinary HTML.
  2. Decide whether the video is decorative or carries information. If it carries information, prepare captions and a transcript.
  3. Prepare a poster image that works as the complete static fallback.
  4. Export a short WebM file and an MP4 fallback without an unnecessary audio track.
  5. Add autoplay muted loop playsinline only for a decorative loop.
  6. Place the video behind the content, add a contrast scrim, and reserve stable dimensions.
  7. Add a labeled play/pause control and keyboard-visible focus styling.
  8. Use a reduced-motion rule that hides or pauses the video.
  9. Defer below-the-fold video and inspect the network panel for avoidable downloads.
  10. Test every failure path before publishing.

Testing and troubleshooting

The video does not autoplay

Cause: an audible track, browser policy, data saver, low-power mode, or a failed load. Fix: confirm the file is muted, keep playsinline, inspect the browser console and network response, and make the play button prominent. Never remove the poster to hide the failure.

Mobile shows a blank or cropped hero

Cause: the source is unavailable, the crop hides the subject, or the video is hidden without a usable background. Fix: verify both source URLs and MIME types, test portrait widths, adjust object-position, and set the poster as the mobile background fallback.

Text becomes unreadable during the loop

Cause: changing frames have insufficient contrast. Fix: strengthen the scrim or gradient, move text to a quieter area, or choose a less busy clip. Check contrast throughout the loop.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The page feels slow

Cause: an oversized file, eager loading, multiple simultaneous videos, or an audio track. Fix: shorten and recompress the asset, remove audio, defer non-hero videos, and measure the waterfall on a slow mobile connection. A poster-only hero may be the better trade-off.

Reduced-motion users still see movement

Cause: the preference is checked only in CSS, while script starts playback, or the media query is missing. Fix: pause in JavaScript as well as CSS, replace the moving layer with the poster, and test the operating-system preference before loading the page.

Screen readers announce confusing content

Cause: decorative media is exposed, or meaningful media has no name and transcript. Fix: use aria-hidden="true" only for genuinely decorative video; otherwise provide an accessible label, captions, transcript, and controls.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

When you need a screenshot of the finished hero for documentation, previews, regression checks, or an AI workflow, ScreenshotNeo provides a single request instead of maintaining browser automation. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the API documentation at https://screenshotneo.com/docs/ for the full option set. This example captures a page as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs').then(({ writeFile }) => writeFile('shot.webp', data));

ScreenshotNeo includes full-page and element captures, dark mode, device presets and custom viewports, retina scale, PDF output, custom CSS and JavaScript, click and wait actions, request blocking, headers and cookies, geolocation and timezone, transparent backgrounds, resizing, configurable caching, signed links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Every feature is on every plan: 1,000 shots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

FAQ

Should a hero video include sound?

Not for a decorative background. Remove the audio track and keep the video muted. If sound is essential, use click-to-play controls with captions and a transcript.

Is a poster image still needed when autoplay works?

Yes. It covers loading delays, blocked autoplay, failed requests, reduced-motion preferences, and browsers that do not support a source format.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use only MP4?

It can work, but supplying WebM plus an MP4 fallback gives browsers more than one compatible option. Test both files and their server MIME types.

What is the safest default for a new site?

Start with a static poster. Add muted autoplay only after confirming that the motion improves the message, remains controllable, and performs acceptably on real mobile connections.

Frequently Asked Questions

How long should a website header video loop be?

Use the shortest clip that establishes the intended atmosphere; a tightly edited loop is preferable to a long sequence. Judge the loop for visible jumps and file size rather than a fixed duration target.

Should the video be hosted on the same domain?

A same-domain file is straightforward to cache and control. A video host or streaming service can help when encoding, delivery, or analytics requirements justify its added configuration; verify its autoplay, poster, privacy, and fallback behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.