Skip to content

prefersReducedMotion

Whether the user asked the system to reduce motion (prefers-reduced-motion: reduce).

Outside a browser, it returns false. To react to changes, use watchMedia('(prefers-reduced-motion: reduce)', listener).

Available since v3.1.5

import { prefersReducedMotion } from '@helpers4/browser';
// or, from the all-in-one package (same code, one install):
import { prefersReducedMotion } from 'helpers4/browser';
prefersReducedMotion(): boolean

boolean — true if animations should be reduced or removed

Use a zero duration when the user asked to reduce motion.

const duration = prefersReducedMotion() ? 0 : 300;

Combine with watchMedia to follow the setting while the page is open.

watchMedia('(prefers-reduced-motion: reduce)', (reduce) => player.setAnimations(!reduce));

View source on GitHub