Use prefers-reduced-motion CSS Media Query to Improve Web Accessibility in your App

Will Mendes
InstructorWill Mendes
Share this video with your friends

Social Share Links

Send Tweet

CSS Media queries are heavily used across web pages for different reasons, such as make your web pages responsive, but what if we can use them to improve web accessibility as well? In this case, you can use prefers-reduced-motion CSS media query to improve web accessibility in your web app by adding this support, respecting the user’s OS option Reduce Motion for people with disabilities.

Will Mendes: [0:00] Let's write a CSS media query to remove the animation. For that, we will use @media and passing prefers-reduced-motion with the value as reduce.

[0:12] Now, we can define these styles to be applied when the CSS media query is enabled. First, we can create the skeleton-loader, and we can add background-image as none. Also, we can add animation as none. With that, as soon as we add a media query with prefers-reduced-motion as reduce enabled, we have this piece of CSS activated and applied in your page.

[0:42] To check the CSS media query in action, you can open accessibility tools and click in Reduce motion. You can enable and disable. When you enable, the animation should not work. When you disable, it'll be back, as expected.