Complex page design often calls for animated elements, and while CSS transitions, canvas 3D rendering, and animated SVG all have their place, a <video> is frequently the more efficient route. Making that video overlay other content requires a transparent background — a feature that is achievable but inconsistent across browsers.
The format search
Image formats fall short
GIF, around for over 30 years, handles small, simple animations but has a limited color space and bloats quickly with colorful, lengthy footage. APNG is the stronger sibling: 24-bit images, 8-bit transparency, backward-compatible with plain PNG so that the first frame renders as a fallback, and broadly supported — though not in Internet Explorer 11. It also fell short on file size and performance. Cycling through a set of PNGs with JavaScript avoids format constraints entirely, but every frame becomes a separate transfer and the animation burns through resources, draining batteries and spinning up fans.
WebM nearly wins
Chrome has supported WebM with an alpha channel for years, and it proved a dramatic improvement: the same sequence at the same frame rate and full color weighed 540 KB against 5.8 MB as a GIF — more than ten times smaller, with better quality and performance. Then the demo met Safari, which lacks WebM transparency on both iOS and macOS and rendered a black background instead. The format worked in Chrome, Firefox, and Edge.
The hybrid answer
Apple announced HEVC video with alpha support in Safari at WWDC 2019, shipping in iOS 13 and macOS Catalina — the same capability WebM offers, on Apple hardware. The pragmatic setup is therefore two formats: HEVC for Safari, WebM everywhere else. That leaves two jobs: producing an HEVC file with alpha, and deciding in JavaScript which file to serve.
Building the WebM
FFmpeg handles the conversion. Inputs are typically image sequences — a frame-by-frame set of alpha-transparent PNGs, which is what a background-removal tool typically emits — though an existing video file works with adjusted options.
ffmpeg -framerate 25 -i unscreen-%3d.png -c:v libvpx-vp9 -pix_fmt yuva420p output.webm
The arguments map to clear purposes. framerate sets how many images make up each second of output. -i unscreen-%3d.png selects the input set; files numbered 001 through 150 matched with a %3d mask. -c:v picks the codec, here VP9 for its broad browser support. -pix_fmt chooses a pixel format that carries an alpha channel; supported formats are listed via ffmpeg --pix_fmts. The trailing argument names the resulting output.webm.
Building the HEVC file
FFmpeg had no HEVC support at the time, and the practical route runs through a Mac: Finder's built-in Encode Media tool, available since macOS Catalina, is free and sufficient. It only accepts specific input formats, so the image sequence must first become ProRes 4444 — a step to get right, since the encoder fails on anything else.
ffmpeg -framerate 25 -i unscreen-%3d.png -c:v prores_ks -pix_fmt yuva444p10le -alpha_bits 16 -profile:v 4444 -f mov -vframes 150 output.mov
The rest needs no terminal. In Finder, right-click the ProRes 4444 file and choose Encode Selected Video Files.

Pick one of the two HEVC quality levels, tick Preserve Transparency, and hit Continue.

The new file is HEVC with alpha; opening it in Safari confirms the transparency survived.

Choosing the right source in the browser
A <video> element handles playback, but normal format fallback via <source /> isn't enough. Some browsers play HEVC or WebM without honoring alpha — Safari 12 plays HEVC with a black background, for instance — so HEVC must reach exactly the right Safari versions. That means setting the src attribute from JavaScript after detection.
Feature detection beats User-Agent sniffing in principle, but no simple API reports transparency support in video. A pragmatic test keys off HEVC-with-transparency availability in iOS 13 and Mac Safari 13: check that navigator.mediaCapabilities exists (older versions lack it) and that the browser is Safari at all. A true result means HEVC is safe; anything else loads the WebM.
function supportsHEVCAlpha() {
const navigator = window.navigator;
const ua = navigator.userAgent.toLowerCase()
const hasMediaCapabilities = !!(navigator.mediaCapabilities && navigator.mediaCapabilities.decodingInfo)
const isSafari = ((ua.indexOf('safari') != -1) && (!(ua.indexOf('chrome')!= -1) && (ua.indexOf('version/')!= -1)))
return isSafari && hasMediaCapabilities
}
In markup, the element pairs transparent sources with a few attributes that reproduce GIF-like behavior:
<video id="player" loop muted autoplay playsinline></video>
<script>
const player = document.getElementById('player');
player.src = supportsHEVCAlpha() ? 'output.mov' : 'output.webm';
</script>
muted— without it, the video won't play until the user interacts.playsinline— on iOS, the video stays in the layout instead of opening fullscreen.loop— the video repeats indefinitely.autoplay— playback starts on page load, provided the video is also muted.
What about old IE?
For most projects, scope the effect to modern browsers (the recent versions of Chrome, Firefox, Safari, and Edge) and hide the video in Internet Explorer; it is rarely a critical element. Where IE 11 support is mandatory, the PNG-sequence approach returns: reduce the frame count and step through images on a timer. Performance is poor, but it works — on one commercial project the video carried enough of the design that degraded IE 11 performance was judged an acceptable trade for the full experience.



