Add background videos and hero videos to your website with Mux. Use this guide when you build a marketing page or a landing page that needs decorative video.
Video has a wide range of uses, but when you're building a marketing page there are two very common choices: Background videos and Hero videos.
This guide covers the best way to add both types of video to your website.
Short, looping clips that autoplay silently, such as hero banners, product previews, or ambient visuals.
Informational videos such as product demos, explainers, customer testimonials, and promotional content. These have sound, playback controls, and can be any length.
The recommended way to add background videos to your website is with the Video.js background video component: the <mux-background-video> custom element for HTML, or MuxBackgroundVideo for React. It streams a Mux HLS URL and is built for decorative video:
Add the following to your page. This example uses a sample video. You'll replace the playback ID with your own in the next step.
<script type="module" src="https://cdn.jsdelivr.net/npm/@videojs/cdn@10/media/mux-background-video.js"></script>
<style>
.hero {
position: relative;
min-height: 480px;
}
.hero-media {
position: absolute;
inset: 0;
pointer-events: none;
}
.hero-media img,
.hero-media mux-background-video {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
--media-object-fit: cover;
}
.hero-content {
position: relative;
}
</style>
<section class="hero">
<div class="hero-media" aria-hidden="true">
<img src="https://image.mux.com/{PLAYBACK_ID}/thumbnail.webp?time=0" alt="" />
<mux-background-video
src="https://stream.mux.com/{PLAYBACK_ID}.m3u8"
crossorigin="anonymous"
></mux-background-video>
</div>
<div class="hero-content">
<h1>Your headline</h1>
</div>
</section>The <img> behind the video acts as a poster while the video loads. The wrapper has aria-hidden="true" because both the poster and the video are decorative.
To use your own video:
Once the upload is complete, copy your Playback ID from the asset details page and replace {PLAYBACK_ID} in your code.
Limit the resolution to match your layout and save bandwidth. Add a max_resolution parameter to the stream URL:
<mux-background-video
src="https://stream.mux.com/{PLAYBACK_ID}.m3u8?max_resolution=720p"
crossorigin="anonymous"
></mux-background-video>In React, pass the same URL to the src prop of MuxBackgroundVideo.
Give viewers a button to stop the background video, and don't play it when their browser asks for reduced motion. To pause it, call pause() on the native video inside it: the element's target property in HTML, or ref in React. See Let viewers stop the motion for an HTML and React example.
For Mux Data, migration from @mux/mux-background-video and the rest of the API, see Add a background video.
You can also serve background videos as static MP4 files instead of using HLS streaming. Each approach has its own strengths.
Why choose MP4:
<video> tagWhy choose HLS (Video.js background video):
MP4 files have a small additional cost for storage. See video pricing for details.
To use MP4 files, enable static renditions when creating your asset. You can do this in both the Mux Dashboard and via the API by including the static_renditions property:
{
"playback_policies": ["public"],
"video_quality": "basic",
"static_renditions": [{ "resolution": "highest" }]
}In the Mux Dashboard: Click Advanced when uploading to reveal the JSON editor, then add the static_renditions property shown above.
Via the API: Include the static_renditions property in your asset creation request.
<video
src="https://stream.mux.com/{PLAYBACK_ID}/highest.mp4"
poster="https://image.mux.com/{PLAYBACK_ID}/thumbnail.jpg"
autoplay
loop
muted
playsinline
></video>The key attributes:
autoplay — Start immediatelymuted — Required for autoplay to work in browsersloop — Replay continuouslyplaysinline — Prevent fullscreen on mobileFor more details on static renditions, see Use static MP4 and M4A renditions.
For product demos, explainers, testimonials, and promotional content, you need a different approach than background videos. These videos are typically longer, users actively watch them, and they need playback controls (play, pause, seek, volume).
The Mux iframe embed (player.mux.com) is built for this use case. You paste one <iframe> into your page, with no JavaScript to install, and get adaptive quality that adjusts to network conditions, full playback controls, and custom branding.
If you'd rather build the player into your own code, for example to customize the UI or control playback from your app, use Video.js instead. Don't install the Mux Player packages (@mux/mux-player or @mux/mux-player-react) for new projects: Mux Player for Web is in maintenance mode.
In the Mux Dashboard:
Once the upload is complete, copy your Playback ID from the asset details page.
Add an iframe to your page. You can also copy this code directly from the Playback and Thumbnails tab on the asset details page in the Dashboard. See Embed videos with an iframe for the parameters you can add to the URL, and Embed parameters for every parameter.
<iframe
src="https://player.mux.com/{PLAYBACK_ID}"
style="aspect-ratio: 16/9; width: 100%;"
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
allowfullscreen="true"
></iframe>You now have a fully functional video player that looks like this.
You can customize the player by adding parameters to the URL.
You can set accent-color to match your brand. This colors the play button, progress bar, and controls:
<iframe
src="https://player.mux.com/{PLAYBACK_ID}?accent-color=%235D3FD3"
style="aspect-ratio: 16/9; width: 100%;"
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
allowfullscreen="true"
></iframe>Mux automatically generates a thumbnail from your video. You can also pick the time of the frame with poster-time, or point poster at your own image URL.
<!-- Default thumbnail -->
src="https://player.mux.com/{PLAYBACK_ID}"
<!-- Thumbnail at 10 seconds -->
src="https://player.mux.com/{PLAYBACK_ID}?poster-time=10"See Get images from a video for more thumbnail options.
Control the player size with CSS:
<iframe
src="https://player.mux.com/{PLAYBACK_ID}"
style="aspect-ratio: 16/9; width: 100%; max-width: 800px;"
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
allowfullscreen="true"
></iframe>If you enabled auto-generated captions during upload, the player automatically shows the captions button once they're ready. No additional configuration needed.
Mux supports auto-generated captions in English, French, German, Italian, Portuguese, Spanish, and many other languages.
See Add subtitles to your videos for more details.
For looping videos, the browser will cache the video and not re-request it on each loop. With short videos, caching typically happens quickly—once the video is fully downloaded, subsequent loops play from cache.
How to verify: Open DevTools, watch the Network tab, and let a video loop a few times. Cached requests may not show up at all, or they may indicate that they were "(from cache)" or "(from disk cache)".