How to Add Video Background in WordPress in HTML
Add a video background in WordPress with the Cover block or custom HTML: autoplay, muted, loop and playsinline, YouTube embeds, file size and a pause button.

To add a video background in WordPress, insert a Cover block, click Add media (or “Upload”) and pick a short MP4 file, then type your heading and button inside the block. WordPress writes the HTML for you: a <video> element with autoplay, muted, loop and playsinline sitting behind your content, plus a colour overlay so the text stays readable. If you want full control of the markup, paste your own <video> tag into a Custom HTML block instead; the code for both routes is below.
Those four attributes are what make a background video actually play on phones, and missing one of them is behind most “it works on desktop but not on my iPhone” reports. This guide covers the Cover block settings, the hand-written HTML version, the YouTube and Vimeo option that arrived in WordPress 7.0, file size and loading speed, and the accessibility work the Cover block does not do for you yet: a pause button and respect for visitors who ask their device for reduced motion. Our team checked each attribute and setting on 18 November 2026 against WordPress 7.1.4, the Gutenberg repository, MDN and the browser vendors’ own documentation.
What is the easiest way to add a video background in WordPress?
The Cover block. It has shipped with WordPress since the block editor arrived, it works in every block theme and most classic themes, and it needs no plugin.
- Open the page or template in the editor. For a homepage hero on a block theme, go to Appearance > Editor and open the front page or home template.
- Add a Cover block where the hero should go.
- In the placeholder, click Upload to add a new file, or Media Library to pick one you already uploaded. Choose an MP4 file. The Cover block accepts images and videos, and it switches to video mode on its own when the file is a video.
- Type your heading, a short line of text and a Buttons block inside the Cover. Those blocks sit on top of the video.
- In the block settings, raise Overlay opacity until the text is easy to read, and set a colour for the overlay.
- Drag the bottom edge of the block, or use the minimum height setting, to set how tall the hero is. A value in viewport units such as
70vhkeeps it proportional to the screen. - Use Focal point to choose which part of the video stays in view when the block crops it on narrow screens.
- If you are on WordPress 6.9 or newer, add a Poster image in the same settings panel. It shows while the video loads and whenever the video cannot play.
- Save, then check the page on a real phone, not only in the editor preview.
That is it for most sites. The rest of this guide is about the details that decide whether the result is fast, readable and usable for everyone.
What HTML does the Cover block output for a video background?
Knowing the markup helps when you debug or style it. This is the shape the Cover block saves, taken from the block’s save function in the Gutenberg repository, trimmed to the parts that matter:
<div class="wp-block-cover" style="min-height:70vh">
<video class="wp-block-cover__video-background intrinsic-ignore"
autoplay muted loop playsinline
src="https://example.com/wp-content/uploads/hero.mp4"
poster="https://example.com/wp-content/uploads/hero-poster.jpg"
style="object-position:50% 50%"
data-object-fit="cover" data-object-position="50% 50%"></video>
<span aria-hidden="true" class="wp-block-cover__background has-background-dim"></span>
<div class="wp-block-cover__inner-container">
<!-- your heading, paragraph and buttons -->
</div>
</div>Three things are worth noticing. The video is a plain HTML5 element, so everything you know about <video> applies. The overlay is a separate empty span layered over the video, which is why it can catch taps meant for the video (more on that in the mistakes section). And the block stores one src only, so it cannot offer a WebM file with an MP4 fallback the way a hand-written <source> list can.
Which video attributes make autoplay work on mobile?
Browsers block videos that start with sound, so a background video has to be silent from the start. Here is what each attribute does, based on MDN’s video element reference:
Attribute | What it does | Needed for a background? |
|---|---|---|
| Starts playback as soon as the browser can, without a click. | Yes |
| Starts with the sound off. Browsers only allow autoplay without a user gesture when the video is muted or has no audio track. | Yes |
| Jumps back to the start when the video ends. | Yes, for a continuous background |
| Plays inside the page on iPhone instead of opening the fullscreen player. | Yes, or iPhones will not autoplay it |
| Image shown before the first frame is ready, and when playback is blocked. | Strongly recommended |
| A hint about how much to download in advance. MDN notes that | No effect with autoplay |
| Shows the browser’s play, pause and volume bar. | No, it clashes with the design; add your own pause button instead |
The rules come from the browsers themselves. Chrome’s autoplay policy says muted autoplay is always allowed. Apple’s WebKit team wrote in its iOS video policy post that muted videos may autoplay without a gesture, and that on iPhone a video without playsinline still requires fullscreen. Leave out either attribute and a phone simply shows the poster or a black box.
One more condition is outside your control: on an iPhone in Low Power Mode, Safari does not autoplay video at all. Your poster image is what those visitors see, which is the best reason to always set one.
How do I add a video background with custom HTML and CSS?
Use this route when the Cover block does not fit: you need a WebM file with an MP4 fallback, your classic theme has no block styles for Cover, or you are building a hero inside a page builder’s HTML widget. Add a Custom HTML block (or edit the template file) and paste the markup. Checked on 18 November 2026:
<section class="hero-video" aria-label="Welcome">
<video class="hero-video__media" autoplay muted loop playsinline
poster="/wp-content/uploads/hero-poster.jpg">
<source src="/wp-content/uploads/hero.webm" type="video/webm">
<source src="/wp-content/uploads/hero.mp4" type="video/mp4">
</video>
<div class="hero-video__content">
<h1>Fresh bread, baked every morning</h1>
<p><a class="hero-video__button" href="/menu/">See today's menu</a></p>
</div>
<button class="hero-video__toggle" type="button" aria-pressed="false">
Pause background video
</button>
</section>Then add the styles in Appearance > Editor > Styles > Additional CSS on a block theme, or Appearance > Customize > Additional CSS on a classic theme:
.hero-video {
position: relative;
min-height: 70vh;
display: grid;
place-items: center;
overflow: hidden;
isolation: isolate;
}
.hero-video__media {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -2;
}
.hero-video::after { /* the dark overlay */
content: "";
position: absolute;
inset: 0;
background: rgb(0 0 0 / 0.55);
z-index: -1;
pointer-events: none; /* let taps reach the video and button */
}
.hero-video__content {
color: #fff;
text-align: center;
padding-inline: 1.25rem;
max-width: 40rem;
}
.hero-video__toggle {
position: absolute;
inset-block-end: 1rem;
inset-inline-end: 1rem;
}
@media (prefers-reduced-motion: reduce) {
.hero-video__media { display: none; } /* poster-free fallback: the overlay colour shows */
}The browser plays the first <source> it supports, so WebM goes first for browsers that handle it and MP4 catches the rest. object-fit: cover fills the box without stretching, the same trick the Cover block uses. The overlay uses pointer-events: none so it never swallows a tap.
If you hide the video for reduced motion as above, give the section a background image or colour so it does not look empty. A still frame from the video, set as a CSS background on .hero-video, works well.
A small script for the pause button
The button in the markup needs a few lines of JavaScript. This version also pauses the video when the visitor has asked for reduced motion and the CSS above is not used. Add it with a code snippets plugin or enqueue it from a child theme:
document.querySelectorAll('.hero-video').forEach((hero) => {
const video = hero.querySelector('video');
const toggle = hero.querySelector('.hero-video__toggle');
if (!video || !toggle) return;
const setPaused = (paused) => {
if (paused) {
video.pause();
} else {
video.play().catch(() => {}); // play() can reject, e.g. in Low Power Mode
}
toggle.setAttribute('aria-pressed', String(paused));
toggle.textContent = paused ? 'Play background video' : 'Pause background video';
};
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
video.removeAttribute('autoplay');
setPaused(true);
}
toggle.addEventListener('click', () => setPaused(!video.paused));
});video.play() returns a promise that rejects when the browser refuses to play, which is why the catch is there. Without it, a blocked play shows up as an uncaught error in the console.
Can I use a YouTube or Vimeo video as a Cover background?
Yes, on WordPress 7.0 and newer. In the Cover block toolbar, choose Embed video from URL and paste the YouTube or Vimeo address. We confirmed in the WordPress source that the embed background type first appears in the 7.0 release, and that 7.1 added a setting developers can use to restrict which providers are allowed. The default list in WordPress 7.1.4 is YouTube, Vimeo, VideoPress, Animoto, TikTok and WordPress.tv.
On the front end, WordPress fetches the provider’s embed code and rewrites the player address with background settings. For YouTube that means autoplay=1, mute=1, loop=1, controls=0, playsinline=1 and a playlist value set to the same video so the loop works. For Vimeo it adds background=1 along with autoplay, muted and loop.
Is it a good idea? It saves upload space and bandwidth on your host, and the provider handles encoding for every device. The trade-offs are real, though:
- The page loads the provider’s player inside an iframe, which is heavier than one small MP4 and pulls in third-party scripts.
- YouTube may show branding or end screens, and visitors see a short loading delay before the video appears.
- Third-party players can set cookies, which matters for consent rules in the EU and UK.
- If the video is removed or made private on the provider’s side, your hero breaks without warning.
For a short decorative loop, a self-hosted MP4 is usually the better choice. If your main goal is to show a watchable video with sound, use a normal embed instead; our guide on embedding a YouTube video in WordPress covers that route, including privacy-enhanced mode and click-to-load players.
How do I keep a video background from slowing down the page?
A background video is often the heaviest thing on the page, and it sits in the first screen, where it can decide your Largest Contentful Paint. web.dev’s LCP documentation says that for a <video> element, the browser counts either the poster image load time or the first frame, whichever comes first. A small, optimised poster therefore helps your LCP directly.
Here is what makes the biggest difference, in order:
- Keep it short. A loop of 6 to 15 seconds is plenty for a background. Nobody watches a hero video for a minute.
- Remove the audio track. The video is muted anyway, so the sound is wasted bytes.
- Lower the resolution. Under a dark overlay, 720p usually looks fine even on large screens. Check it with your own footage.
- Compress hard. Background footage with soft motion tolerates a lot more compression than a talking-head video.
- Move the index to the front of the MP4 file (the
faststartflag) so playback can begin before the whole file arrives. - Set a light poster image, ideally WebP or AVIF, at the size the hero displays.
If you have FFmpeg installed, these two commands produce a silent 720p MP4 and WebM pair. Checked on 18 November 2026 against the FFmpeg documentation:
# MP4 (H.264), no audio, 720p tall, index moved to the front.
ffmpeg -i hero-original.mov -an -vf "scale=-2:720" \
-c:v libx264 -crf 28 -preset slow -movflags +faststart hero.mp4
# WebM (VP9), no audio, 720p tall.
ffmpeg -i hero-original.mov -an -vf "scale=-2:720" \
-c:v libvpx-vp9 -crf 35 -b:v 0 hero.webm-an drops the audio, scale=-2:720 sets the height to 720 pixels and keeps the width even, and -crf sets quality (a higher number means a smaller file). Compare the result on screen and nudge the CRF up or down; there is no single right value for every clip.
Check the file size in Media > Library after upload. If it is tens of megabytes, go back and cut it. Also keep in mind that your host’s upload limit (upload_max_filesize in PHP) may reject a large file outright. For the rest of the first screen, our guide to removing render-blocking CSS and JavaScript in WordPress covers the other common LCP drags.
Are video backgrounds accessible?
They can be, but the Cover block alone does not get you there today. Two requirements matter.
Visitors must be able to pause it
WCAG success criterion 2.2.2, Pause, Stop, Hide, says that moving content which starts automatically, lasts more than five seconds and appears alongside other content needs a way to pause, stop or hide it. A looping background video meets all three conditions. The Cover block has no pause control: a Gutenberg issue asking for video controls on Cover has been open since February 2022, and a later request for a pause button was closed as a duplicate of it. Until that lands, add a pause button yourself, as in the custom HTML example above.
Respect reduced motion
Many people turn on “Reduce motion” in their operating system because animation makes them dizzy or distracts them. Browsers expose that choice through the prefers-reduced-motion media query. In WordPress 7.1.4, the Cover block’s stylesheet only uses it to turn off the fixed (parallax) background effect. It does not stop a video.
That is changing. The Gutenberg plugin added code that stops autoplay for embedded background videos in version 24.2 and for uploaded background videos in version 24.3, released on 28 October 2026, both only when the visitor prefers reduced motion. Those changes reach WordPress core in a later release; until your site runs one that includes them, use the CSS or script above, or the Gutenberg plugin itself.
Keep the text readable
Text over moving footage needs strong contrast at every frame, not just the first one. Use a dark overlay (opacity around 50 to 70 percent works for most bright footage), large text and short lines. Never put essential information only in the video; anything a visitor must know belongs in the text on top.
Common mistakes people report
These come up again and again in the Gutenberg issue tracker and the WordPress.org support forums. We checked each linked thread on 18 November 2026.
- The video shows on desktop but not on phones. One user’s Cover block video played in the editor and on desktop but did not appear on mobile; the forum moderator called mobile video backgrounds one of the Cover block’s limitations. Before giving up, check the file is H.264 MP4, small, and has a poster. Thread: Homepage Cover Video.
- A black box on iPhone. A looping MP4 background played on desktop and Android but showed only a black box on iPhones. A moderator pointed out that H.264 MP4 is supported by Safari and suggested checking the browser version first. Thread: Homepage video not displaying on Apple iPhone. The original Cover block bug for iOS, fixed by adding
playsinline, is Gutenberg issue #17479. - The play button cannot be tapped in Low Power Mode. When iOS blocks autoplay, Safari shows a play button on the video, but the Cover block’s overlay span sits on top and catches the tap, so nothing happens. Reported in Gutenberg issue #64154, still open. A CSS rule giving
.wp-block-cover__backgroundpointer-events: noneis a common workaround; test it on your theme. - No way to pause the video. Editors complain that the looping video keeps playing while they work, and accessibility reviewers point to the missing pause control on the front end. Tracked in Gutenberg issue #38975.
- Dark text on a dark video. With an image background, Cover picks a contrasting text colour automatically. With a video background it does not at first, so text can start out black on dark footage. Reported in Gutenberg issue #36549; set the text colour yourself.
- Trying to make the video “fixed” like a parallax image. The Fixed background setting applies to images only, and requests to allow it for video are still open in Gutenberg issue #52585. Fixed backgrounds also do not work properly on iOS Safari, so a normal scrolling video is the safer design.
Cover block, custom HTML or a plugin: which should you use?
Option | Best for | Watch out for |
|---|---|---|
Cover block with an uploaded video | Most sites; no code, works in every block theme | One file format only; no pause button yet |
Cover block with a YouTube or Vimeo URL | Long or large videos you already host there; WordPress 7.0+ | Heavier iframe, provider branding, cookie consent |
Custom HTML and CSS | WebM plus MP4 fallback, your own pause button, full control | You maintain the code and styles |
A page builder or block plugin | Sites already built with that tool | Extra scripts on every page; lock-in to the plugin |
Our default advice: start with the Cover block and a well-compressed MP4, add a poster image, and add a pause button with a few lines of code. Reach for custom HTML when you need the WebM fallback or tighter control. If you are laying out the content on top of the video, the Group block is the cleanest way to keep the heading, text and buttons together inside the Cover.
Frequently asked questions
What video format should I use for a WordPress background?
MP4 with H.264 video plays in every current browser, so it is the safe single choice for the Cover block. With custom HTML, add a WebM version first and keep MP4 as the fallback.
Why does my background video have sound in the editor but not on the site?
The Cover block always saves the video with muted, because browsers block unmuted autoplay. If you need sound, use a Video block with controls instead of a background.
Can I set a different video for mobile?
Not inside one Cover block. A common approach is two Cover blocks, one with the video and one with a still image, shown and hidden at a breakpoint with CSS. Keep in mind that a hidden autoplay video may still be downloaded by some browsers, so test with your browser’s network panel.
Will a video background hurt my SEO?
Not by itself. It can hurt your Core Web Vitals if the file is large, and slow pages lose visitors. Keep the file small and set a poster image, and it is no worse than a large hero photo.
Does a video background need captions?
A silent, decorative loop with no information in it does not need captions. If the video carries meaning, such as a product demo, it should not be a background at all; put it in a Video block with controls and captions.
Where to go from here
A good video background is short, silent, compressed, has a poster, and can be paused. The Cover block gets you most of the way in a couple of minutes; the remaining pieces are a pause button and a reduced-motion rule, which take a few lines of code until WordPress core ships its own. If you build a lot of hero sections, save your finished Cover as a pattern so every page starts from the same tested setup. Our guide to WordPress block patterns shows how.
Plugins we build and run
We maintain these ourselves, which is why we can support them on your site.
- BuddyNextThe self-hosted community engine for WordPress
- BuddyXFree community theme, Pro when you outgrow it
- ReignPremium community theme. Add pieces, build anything
- JetonomyCommunity forum and Q&A for WordPress
- EventonomyEvents and RSVPs for WordPress communities
- LearnomyCourses and learning communities on WordPress
- ListoraDirectories and listings your members can browse
- SnipShareCode sharing built for developer communities
- WB Ad ManagerAd placements that turn traffic into revenue
- WP Career BoardA job board your community actually uses
- WP Sell ServicesSell services with offers, orders, and payouts
- MediaVersePhotos, video, and media albums for members
- WB GamificationPoints, badges, and rewards that keep members active
- Product RoadmapPublic roadmaps with voting your users trust
- KanbanomyProject management with a client portal, on your own WordPress site


