Use Media Queries to Detect a User Preference for Motion

Jhey Tompkins
InstructorJhey Tompkins
Share this video with your friends

Social Share Links

Send Tweet

We can use the media query prefers-reduced-motion to detect a user's preference for motion. This is particularly useful when we have users that may have vestibular disorders. In these cases, we can detect it and set motion speed to zero.

Instructor: [0:00] Our tic-tac-toe board currently uses motion on the page, and this might not be suitable for all users. To detect this, we can use the media query prefers-reduced-motion. In our demo, all motion is powered by this drawSpeed variable. When you use the prefers-reduced-motion, we can set the drawSpeed to seconds.

[0:19] Now when we check our demo, it still works as before, but using the rendering panel of DevTools, we can emulate prefers-reduced-motion. If we reload our page, there's no motion to draw any of the elements.

[0:32] In review, we can use the media query prefers-reduced-motion to detect our users' preferences for motion. These users may have vestibular disorders and would prefer no motion at all or reduced motion. In those cases, we can do things such as reduce motion duration to seconds.