motionPreference()
Follow the reduced-motion setting.
Try the example
Play the sample transition. Its duration follows your system’s reduced-motion setting. Change that setting to see the value update while this page stays open.
Follows your system setting.
Add it to your project
- Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
- Connect the behavior. Copy the JavaScript tab and call its exported
mount(element)after your component’s elements exist. Replace simulated delays and data operations with your own application code. - Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.
API and lifecycle
Subscribe to the system prefers-reduced-motion setting. onChange runs with the initial preference and whenever it changes. reduced exposes the current setting; duration(ms) returns zero when reduced motion is requested.
- Interface
onChange; duration(ms), reduced, destroy- Lifecycle
- Keep a subscription for the view that uses it. destroy() removes the media-query listener when the view is removed.
Accessibility and safety
Implementation notes
Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.
Reduced motion should preserve the outcome while reducing animation. Do not hide content or make completion depend on an animation event.
What to check
Change the system setting while the page is open. Confirm the listener updates and every interaction still reaches its final usable state.