Skip to: Content or Footer

Accessibility, checking if user prefers reduced motion

Created on
Updated on
Approx ~5 minutes reading time for 988 words.

Introduction

Animations on the web, love or loathe them, are everywhere. For a significant number of the worlds population this can have an impact on their accessibility needs.

How can simple motion cause problems?

Imagine if viewing animations were to cause you to lose your balance, this is possible with a malady know as vestibular disorder.

Your Vestibular system is the sensory mechanism in the inner ear that detects movement of the head and helps to control balance.

Dennis Gaebel / a11yproject.com

Depending on the type and intensity of the animation it can also trigger epilepsy and migraines. To find out more read this list of vestibular disorders.

Configure your settings

Each relatively up-to-date Operating System has settings to allow reducing motion. In general this means turning it off altogether. Below are the instructions for Apple Mac Monterey.

  1. Open System Preferences and select Accessibility (the blue circle, 2nd row in the centre.)
  2. Select Display under the Vision section.
  3. Click the Reduce motion checkbox.

An example of pulsing animation (slowed down)

You can imagine after understanding the effects of vestibular disorder what the example below would do if speeded up. If you’ve already tried out configuring your settings to reduce motion it should be in a static state.

Note: The preference setting depends on the browser honouring that choice.

The CSS code

The animation element is activated in a div with an id of reduce-motion-example. In order to target and activate the prefers-reduced-motion code we use;

@media (prefers-reduced-motion: reduce) {
  #reduce-motion-example {
      animation: none;
  }
}

The @media query will check for a preference and if set as above, will override the animation settings.

While @media (prefers-reduced-motion) will work in most cases, it is best for clarity and better support to add :reduce.

Target the inverse

There’s usually more than one way to do things. If the browser understands the @media query and the user has not set a preference for reduced motion we can use the following code to only activate the animation using no-preference.

@media (prefers-reduced-motion: no-preference) {
  #reduce-motion-example {
      animation: stretch 10s ease-out 0s alternate infinite;
  }
}

In conclusion

Browsers are enabling Web Developers of modern websites more access to System Preferences allowing them to respect Users Preferences. This is a key factor to bear in mind moving forwards to make the web more accessible for everyone.

// End of Article

Article Information

Category: Technical
Topic: #Accessibility

Dave Barr

Scottish Expat who has 20+ years experience of Web Development and is continually on the look out to improve his skill sets. Learning new and innovative solutions for current requirements in the world of IT, Web Development and eCommerce.

About Dave Barr

Scottish Expat who has 20+ years experience of Web Development and is continually on the look out to improve his skill sets. Learning new and innovative solutions for current requirements in the world of IT, Web Development and eCommerce.

Read more about Dave

Back to Top

Click to Copy