How to Use prefers-reduced-motion with HTML Video
Published
For an optional video loop, leave autoplay out of the HTML and check prefers-reduced-motion before starting playback in JavaScript. Keep the player’s controls available. Visitors who request reduced motion can then see a still preview and choose whether to play the clip.
Keep pause controls for everyone
Reduced motion is a preference some visitors set in their operating system or browser. It is useful input for your playback decision, but people without that setting may also need to stop a distracting loop.
W3C’s Pause, Stop, Hide guidance requires a way to pause, stop, or hide nonessential moving information that starts automatically, lasts more than five seconds, and appears alongside other content. A short clip looping continuously still produces ongoing motion. Checking a preference does not replace the pause control.
For a tutorial or narrated demo, click-to-play is often the simpler choice. Use the example below for an optional preview whose main information is also explained in nearby text. Add captions when speech or meaningful audio is part of the clip.
Start with a paused, usable player
Replace the example file paths and dimensions with your assets. This markup deliberately has no autoplay attribute:
<video id="filter-preview"
controls muted loop playsinline preload="none"
poster="/media/filter-preview.webp"
width="1280" height="720"
aria-label="Preview of filtering a results list"
style="display:block;width:100%;height:auto">
<source src="/media/filter-preview.mp4" type="video/mp4" />
</video>
<p>Choose a category to narrow the results list.</p>
The poster supplies a preview before playback; see the poster image guide for preparing it. Native controls let visitors start and pause the video even if the script fails or JavaScript is disabled. preload="none" is a loading hint, not a guarantee that the browser makes no media requests.
Check the preference before attempting autoplay
Place this script after the video markup. It attempts muted playback once when reduced motion is not requested. It also pauses the video if that preference changes to reduce while the page is open:
<script type="module">
const video = document.querySelector("#filter-preview");
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
motion.addEventListener("change", (event) => {
if (event.matches) video.pause();
});
if (!motion.matches) {
video.play()
.then(() => {
if (motion.matches) video.pause();
})
.catch(() => {
// Keep the native controls available for manual playback.
});
}
</script>
MDN’s matchMedia reference explains the initial matches check. The MediaQueryList change event handles preference changes without a reload. The second check, after playback starts, covers a preference change while the play request was pending.
Keep automatic restarts out of the pattern
Changing the preference back does not restart this video. Visitors use the player controls when they want to resume. The script also leaves a manual pause alone; it has no timer or scroll handler that starts the clip again.
Visitors with reduced motion enabled can still choose Play. This implementation changes the default behavior rather than removing access to the video. When an already-playing video is paused, it can remain on its current frame; pausing does not necessarily restore the poster.
Handle blocked playback separately
Muted playback can still be declined. The play() method returns a Promise that rejects when playback cannot start. The catch handler leaves the controls available and avoids an unhandled rejection. If manual playback fails too, use the playback troubleshooting guide to check the source and server response.
Test playback choices on the public page
- Reduced motion enabled before loading: confirm the clip stays paused and the preview and surrounding explanation are useful.
- No reduced-motion preference: check automatic playback when allowed, then pause manually. Confirm it stays paused.
- Preference changes during playback: enable reduced motion and check that playback stops. Turn it off again and confirm the clip stays paused until you choose Play.
- Manual controls: use keyboard and touch to start and pause, including with reduced motion enabled.
- Autoplay blocked or JavaScript disabled: confirm manual controls still work. Test these cases separately; blocking autoplay does not disable JavaScript.
A CSS rule that removes transitions does not call pause() on a video. Check the actual playback state as well as the surrounding animations, especially if another component also controls the same player.