Menu

Reduced motion in Framer Motion: what I learned adding it to 150+ files
📰

Reduced motion in Framer Motion: what I learned adding it to 150+ files

DEV Community: react·Saurabh Chauhan·3 days ago
#GqEDOFqD
#devtoreact#devto#dev#motion#reduced
Reading 0:00
15s threshold

Most sites handle reduced motion with one CSS rule. beUI's site has it too:

@media ( prefers-reduced-motion : reduce ) { * , * : : before , * : : after { animation-duration : 0.01ms ! important ; transition-duration : 0.01ms ! important ; } }

Enter fullscreen mode

Exit fullscreen mode

It's worth having, but on a Framer Motion site it isn't enough. Turn on "Reduce motion" with only this rule in place, and drawers still slide in, tabs still spring and counters still roll.

That CSS only shortens CSS animations and transitions. Framer Motion works out each frame of a spring in JavaScript and writes the result to the element's style, so the media query never sees it.

I build beUI , a library of animated React components, and more than 150 of its files now read the reduced motion setting. Here's what I learned doing that.

Start with the hook, and handle null

import { useReducedMotion } from "motion/react" ;

const reduce = useReducedMotion ( ) ??…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.