[WEB ANIMATION](https://www.kirupa.com/css_animations/index.htm) [BOOK](https://www.kirupa.com/book/animation_in_html_css_and_javascript.htm) [VIDEO](https://www.youtube.com/channel/UCZCQ3LXtU3IUzMBQBqN69KQ) # Respecting Reduced Motion by [kirupa](https://www.kirupa.com/me/index.htm) | filed under [Web Animation](https://www.kirupa.com/html5/learn_animation.htm) **TL;DR:** The prefers-reduced-motion media feature tells our CSS and JavaScript when someone has asked their device for less motion. Reduce shouldn't mean remove: we swap big movement for fades, drop decorative motion like parallax, keep motion that carries information like progress bars, and listen for the setting changing while the page is open. - Writing the calm version first and adding big motion inside prefers-reduced-motion: no-preference means anything we forget to handle stays calm. - Our inner ear keeps track of balance, and motion on a screen that disagrees with it can bring on dizziness, nausea, or a migraine. - A change listener on the matchMedia result updates the page the moment someone flips the setting, without a reload. - Chrome, Firefox, and Safari developer tools can all pretend reduced motion is on, so we can test the calm versions quickly. Motion is one of the best tools we have for making a page feel alive. A notification slides in, a card flips over, the background drifts as we scroll. For a lot of people, that's delightful. For some people, the very same motion makes the room feel like it's spinning, and a fancy scroll effect can mean a headache or nausea that lasts well after they've closed the tab. Fortunately, people who need less motion can tell their device about it, and our pages can listen. In this article, we'll look at how to detect that request in CSS and JavaScript, what "less motion" should actually mean (hint: it's not "no motion"), and how to handle the common kinds of motion we put on our pages. Here's a little lab with four kinds of motion that we'll keep coming back to. Switch between **Full** and **Reduced** to see how each one responds: [Live demo: Four kinds of motion: a sliding notification, a bouncing ball, a scrolling ticker, and a progress bar, with buttons to switch between full and reduced motion](https://www.kirupa.com/animations/examples/reduced_motion_lab.htm) Onwards! ## What Is prefers-reduced-motion? Every major operating system has an accessibility setting that asks apps to tone down their animations. On a Mac, it's a switch called **Reduce motion**. When someone turns it on, the operating system's own animations calm down, and the browser passes the request along to every web page it shows. Pages can check for it using a CSS media feature called **prefers-reduced-motion**: ![Someone turns on Reduce motion in their operating system's accessibility settings. The browser passes it to every page as prefers-reduced-motion: reduce, which our CSS and JavaScript can check.](https://www.kirupa.com/animations/images/rm_flow.png) The `prefers-reduced-motion` media feature has two possible values. It's `reduce` when someone has turned the setting on, and `no-preference` when they haven't. That second value doesn't mean the person loves motion. It just means they haven't told us anything either way. Where the setting lives depends on the device. According to [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion), here's where to find it at the time of writing: - macOS: System Settings > Accessibility > Display > Reduce motion. Starting with macOS Tahoe, it's under Accessibility > Motion instead. - iOS and iPadOS: Settings > Accessibility > Motion > Reduce Motion. - Windows 11: Settings > Accessibility > Visual effects, where turning off Animation effects asks for reduced motion. - Android: Settings > Accessibility > Remove animations. - GNOME on Linux: Settings > Accessibility > Seeing > Reduced animation. Browser support is a non-issue. Chrome, Edge, Firefox, and Safari have all supported `prefers-reduced-motion` since early 2020, so we can use it everywhere today. ## Who Does Reduced Motion Help? Deep inside our ears is the **vestibular system**, the part of our body that keeps track of balance and which way is up. It works together with our eyes. When our eyes say we're moving and our inner ears say we're sitting still, our brain gets two conflicting reports, and for some people that mismatch causes dizziness, nausea, or a migraine. People with vestibular disorders are especially sensitive to it, and big motion on a screen, like parallax scrolling, zooming, or things sliding across the whole page, is a common trigger. This affects a lot more people than we might expect. The [Vestibular Disorders Association](https://vestibular.org/article/what-is-vestibular/about-vestibular-disorders/) points to a large US study where about 35% of adults aged 40 and older, roughly 69 million people, showed signs of vestibular dysfunction in a balance test. Not all of them turn on a reduced motion setting, of course, but it gives a sense of scale. Motion can also be distracting. Someone with an attention-related condition can find it hard to read a paragraph while something keeps moving next to it. And some people turn the setting on simply because they find all the swooshing annoying, which is a perfectly good reason too. ## How Do We Check for It in CSS? The `prefers-reduced-motion` media feature works like any other media query. There are two ways to use it, and they come at the problem from opposite directions. The first way is to write our animations as usual and then turn them down when someone asks for less motion: ```css .toast { animation: slideIn 0.6s ease-out both; } @media (prefers-reduced-motion: reduce) { .toast { animation: fadeIn 0.3s ease-out both; } } ``` The second way flips it around. The calm version is the default, and the big motion only gets added when the person hasn't asked for less: ```css .toast { animation: fadeIn 0.3s ease-out both; } @media (prefers-reduced-motion: no-preference) { .toast { animation: slideIn 0.6s ease-out both; } } ``` Both work, but the second approach has a nice safety property. If we forget to handle an animation, or the browser doesn't understand the query, the person gets the calm version. Treating big motion as an extra layer on top of a page that already works is a good habit, and it's the same idea behind how we handled view transitions. ## How Do We Check for It in JavaScript? Not all motion lives in CSS. Animations driven by `requestAnimationFrame`, canvas drawings, and scroll effects all run in JavaScript, so we need to check the setting there too. The `matchMedia` method takes the same media query we'd use in CSS and gives us back an object whose `matches` property tells us whether it's true right now: ```js const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); if (reduceMotion.matches) { // Use the calm version } ``` There's a catch. People can change the setting while our page is open, and checking `matches` once when the page loads won't notice. To keep up, we listen for the `change` event: ![A timeline. The page loads with no preference and a ball animates along. Partway through, someone turns on Reduce motion. A change event fires right away, and the ball stops where it is, without a reload.](https://www.kirupa.com/animations/images/rm_change_event.png) The `change` event fires the moment the setting flips, with no reload needed. Here's how we listen for it: ```js reduceMotion.addEventListener("change", () => { if (reduceMotion.matches) { stopTheFancyStuff(); } else { startTheFancyStuff(); } }); ``` You may run into older code that uses `addListener` instead. That method is deprecated, and `addEventListener` has worked on these objects in every major browser since Safari 14 in 2020. To see this in action, open the lab at the top of this article with **Follow my device** selected, and then flip the setting on your device. The lab updates right away. ## What Should "Reduce" Actually Mean? It's tempting to treat `reduce` as an off switch and kill every animation on the page. That's better than nothing, but it's not what people are asking for. The setting is called *reduce* motion, not *remove* motion. A lot of animation exists to help people understand what changed, like a new item appearing in a list or a panel opening. Removing it entirely can make a page more confusing. The motion that causes trouble is usually movement: things sliding, zooming, spinning, or moving at a different speed than the page as we scroll. Fades, color changes, and blurs that don't change an element's size, shape, or position are much gentler. So instead of removing an animation, we can often swap its movement for a fade: ![Two film strips. Full motion: over 0.6 seconds, the Saved! notification slides in from the right edge and settles into place. Reduced motion: over 0.3 seconds, it stays in that same spot and fades in from invisible to fully visible.](https://www.kirupa.com/animations/images/rm_swap.png) Both versions tell us the same thing: something was saved, and here's the message. The reduced version just gets there without a trip across the screen. It's also shorter, finishing in 0.3 seconds instead of 0.6. Some motion should stay no matter what, because the motion *is* the information. A progress bar that fills up tells us how much of an upload is done. Dragging a card should move the card along with our finger, since that's what the person is doing. A video someone deliberately pressed play on should keep playing. Putting it all together, most motion falls into one of three buckets: ![Three columns. Remove it: parallax, background drift, and scrolling tickers. Swap it for a fade: slide-ins, zooms, and page transitions. Keep it: progress bars, a video someone chose to play, and dragging that follows a finger.](https://www.kirupa.com/animations/images/rm_triage.png) The [Web Content Accessibility Guidelines](https://www.w3.org/WAI/WCAG22/Understanding/animation-from-interactions.html) (aka WCAG) describe the same idea. Success criterion 2.3.3, Animation from Interactions, asks that motion animation triggered by an interaction can be turned off, unless the animation is essential to the information or the functionality. Its definition of motion animation leaves out color changes, blurs, and opacity changes that don't change an element's perceived size, shape, or position, which is why fading is such a safe fallback. That criterion is at the strictest AAA level, but there's a related one at level A, the level every site is expected to meet. Criterion 2.2.2, Pause, Stop, Hide, says anything that moves, blinks, or scrolls on its own for more than five seconds alongside other content needs a way to pause, stop, or hide it. That applies whether or not someone has turned on the reduced motion setting, which is why the ticker in our lab has a Pause button. ## How Do We Handle Common Kinds of Motion? Let's go through the kinds of motion that show up on pages all the time, and what to do with each one when someone asks for less. ### CSS Animations and Transitions For animations and transitions that move things, swap the movement for a fade or a quick color change, like we saw earlier. For a transition on `transform`, we can keep the transition on properties like `opacity` and drop the transform: ```css .card { transition: opacity 0.2s; } @media (prefers-reduced-motion: no-preference) { .card { transition: opacity 0.2s, transform 0.4s; } .card:hover { transform: translateY(-8px) scale(1.03); } } ``` You'll often see a catch-all snippet that sets every animation and transition duration to almost nothing when `reduce` is on. It's a decent safety net for a big existing site, since nothing will fly around. The downside is that it also flattens the motion worth keeping, like progress indicators, so it's better to handle the important animations on purpose and keep the catch-all as a backup. ### requestAnimationFrame Loops An animation driven by `requestAnimationFrame` runs our code on every frame, so the simplest approach is to check the setting inside the loop and skip the movement when it's on. Here's the core of the bouncing ball from the lab: ```js const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); function animate(timestamp) { if (!reduceMotion.matches) { moveTheBall(timestamp); } requestAnimationFrame(animate); } requestAnimationFrame(animate); ``` Because the loop checks `matches` on every frame, the ball stops and starts as soon as the setting changes, without any extra event listeners. For animations that run all the time, like a looping background effect, another good option is to start them paused when `reduce` is on and show a Play button. The demos in [Random Colors and a Bouncy Square](https://www.kirupa.com/animations/color_changing_bouncing_square.htm) and [Collision Detection](https://www.kirupa.com/animations/collision_detection.htm) do exactly that. If you're new to animation loops, [Animating with requestAnimationFrame](https://www.kirupa.com/html5/animating_with_requestAnimationFrame.htm) covers how they work. ### Autoplaying Video Background videos that start playing on their own are a lot of motion, and they often fill the whole screen. When someone asks for less motion, the friendly thing to do is to show the video's poster image and let them decide whether to press play: ```js const video = document.querySelector("#heroVideo"); const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); if (reduceMotion.matches) { video.removeAttribute("autoplay"); video.pause(); video.controls = true; } ``` Even without the setting, a video that plays for more than five seconds next to other content needs a visible way to pause it, so a pause button is worth having either way. ### Smooth Scrolling Smooth scrolling animates the page from one spot to another instead of jumping, which can mean whole screens of content flying past. We only turn it on for people who haven't asked for less motion: ```css @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } } ``` When we scroll from JavaScript, the `behavior` option does the same job: ```js const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); section.scrollIntoView({ behavior: reduceMotion.matches ? "auto" : "smooth" }); ``` ### Parallax and Scroll Effects Parallax, where layers move at different speeds as we scroll, is one of the most common triggers for vestibular reactions, and it's almost never essential. When `reduce` is on, the best move is to skip it entirely and let everything scroll together. The scrolling itself is fine, since the person is doing it. It's the extra movement on top that causes trouble. If you're building scroll effects, [Smooth Parallax Scrolling](https://www.kirupa.com/html5/smooth_parallax_scrolling.htm) shows how they work under the hood. The same thinking applies to view transitions, which we cover in [Meet the View Transitions API](https://www.kirupa.com/animations/view_transitions_api.htm). ## How Do We Test It? The most realistic test is to turn the setting on in our own operating system, using the locations listed earlier, and then use our site for a while. That's also a great way to build empathy for the people who browse like that every day. For quicker checks, every major browser's developer tools can pretend the setting is on for just the current tab: - In Chrome and Edge, open the Rendering panel and set **Emulate CSS media feature prefers-reduced-motion** to `reduce`. Typing "reduced motion" into the Command Menu finds the same option. - In Firefox, the Inspector's Rules view has an emulation menu with a reduced motion option. We can also set the `ui.prefersReducedMotion` preference to 1 in `about:config`. - In Safari, the Elements tab of Web Inspector has an **Override user preferences** button that includes reduced motion. For automated tests, browser tools like Playwright can launch a page with reduced motion turned on, so we can check that our calm versions keep working as the code changes. The demos on this page were tested that way. ## A Real Example: kirupa.com This site follows its own advice. If you open **Customize theme** from the header, you'll find a **Background icons** section with a **Motion** setting. It controls the little icons that float in the empty space beside the text on wider screens, and it has six choices: Off, Still, Calm, Playful, Lively, and Drift. The Still choice keeps the icons in place so they simply scroll with the page, and the others add more and more motion, from a gentle drift while we scroll to icons that wander around on their own. When your device asks for less motion, the icons stay still no matter which choice is picked, and the Customize theme panel says so: "Your device asks for less motion, so they stay still." The site also listens for the `change` event, so flipping the setting while a page is open settles the icons right away. And because the Motion setting lives on the site itself, people who never touch their operating system's settings can still turn things down (or off) whenever they want. ## Conclusion Respecting reduced motion takes surprisingly little code. A media query in CSS, a `matchMedia` check with a `change` listener in JavaScript, and we know what the person wants. The thoughtful part is deciding what to do with that information. Remove the decorative motion, swap big movement for fades, and keep the motion that carries real information, like a progress bar filling up. Most people will never notice any of this, and that's kind of the point. The people who do need it will notice the absence of a headache, which is about the nicest thing a web page can give them. Before you go, here are a few things you can do: 1. Test your knowledge by taking the quiz below. 2. Read the next article in the series, [Restarting a CSS Animation](https://www.kirupa.com/animations/restarting_css_animations.htm), or check out some related content: - [Toggling Animations On and Off](https://www.kirupa.com/html5/toggling_animations_on_off.htm). Give people a button that pauses and resumes animations. - [Meet the View Transitions API](https://www.kirupa.com/animations/view_transitions_api.htm). Animate between views, with a gentle fade for reduced motion. - [Smooth Parallax Scrolling](https://www.kirupa.com/html5/smooth_parallax_scrolling.htm). Build a parallax effect, the kind of motion worth toning down. 3. Stuck on something, or curious about a detail we skipped? [Ask on the forums](https://forum.kirupa.com/), and we'll help you out. ## Test your knowledge! [Take the Respecting reduced motion Quiz](https://www.kirupa.com/quizzes/respecting_reduced_motion.htm). Practice with 8 multiple-choice questions and an explanation after every answer.