New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's best for prefers-reduced-motion?
#11
Comments
|
Here is another variant I have encountered (not tested): @media (prefers-reduced-motion: reduce) {
* {
animation-duration: 0s !important;
transition: none !important;
scroll-behavior: auto !important;
}
} |
|
I found the tweets I snagged this code from... by @scottjehl |
|
The Media Queries 5 spec defines The issue where this CSS feature was created is here: There's a bit of discussion about enforcing this with the browser itself, but that idea was set aside:
Reading the debate in the CSSWG issue is a good way to think about the use cases and options. I'm left thinking we should include this in Remedy, not because the CSSWG "got it wrong", but because this is a good default for all of the web developers (Authors) who don't bother thinking about Now if we could only make this apply to all the auto-play video/gif/animated advertisements. (UA's should enforce this by turning all gifs and videos into NOT autoplaying. Can we do that in the CSSWG @frivoal @fantasai ?) Oh, which still leaves the question of how.... (I just also want to consider if, for a bit, too / think about why the CSSWG didn't put the burden of this on the browser to enforce.) |
|
How about this? |
|
No, CSS does not have control over autoplay. Setting both transition/animation to none and transition/animation-duration to 0 seems redundant? |
|
Setting That said, an at-the-time WebKit engineer cautioned me against this sort of CSS when I mentioned it on Twitter 2 years ago:
So this might be a thornier issue than it first seems. |
|
@tigt For instance: to detect from the JavaScript side when an element has changed state of one of its properties; or to detect that it has just switched from invisible to visible/rendered state. The second in particular is a necessity for a few complicated solutions. Including some strategies used to polyfill or provide fallback solutions for the |
|
This is definitely a more complex problem than it initially seems as has been stated above. In my research so far I haven't found a blanket solution that isn't without issues. But trying for a "least risky" option to include in this reset could provide a decent starting point. (And help spread knowledge that such a media query exists.) Most have been mentioned in this thread already, but here's a summary based on my research so far that might be helpful for this decision: The almost 0s duration:
Based on this test, animation events still fire, but the timing of when they fire may still be an issue for some uses. This nearly 0s duration approach might be an acceptable way to go for this project. It’s not without issues or risks, but if it can be assume that this base stylesheet is being implemented at the beginning of a project, the author could be encouraged to compose all CSS-based animations with this reduced rule in mind from the start. (Admittedly, that is still a big assumption.) none:
Very short duration:
Steps:
Two other points to consider: Whatever this rule ends up being, it will be favoring stopping all animation by default which can be beyond what is needed in many situations. Both the WebKit blog post on
|
|
Thank you Val. So, to be clear, is likely a bad solution, because in certain browsers, the state change will never happen. So, for example, if someone has applied a fade to a hover color, instead of immediately getting the hover color (rather than a fade), with a 0 duration, the user might get no hover color — things just staying without a color change at all. So that's off the table. It's good to know why. Seems to me like we should do this: and nothing else is required. (Unlike the recent code in the project that was more complex. There are many, many situation where that won't work, but it's also likely that 90% of websites only use animations at this point for things like hover color transitions, and other slight details. Hopefully anyone building more complex animations will know to think through what happens when In fact, the alarm that people might have from us doing this might generate enough buzz and conversation that the message will get around. Pay attention to The other choice is to not do this at all. To leave it all up to the developers. I just don't like that. I'd rather risk breaking fancy animations than risk no websites bothering to write good code for people who can't take motion very well. (And I say this as one of those people — motion on websites makes me nauseous. Really any looping motion, like repeating animated gifs in conference presentations. Ugh. Sadly, this setting will not help with the worst problems — ads with motion. Reader Mode is the only solution to that, atm.) Sadly using I'm going to change the code. Let's keep talking about it. |
|
Should the code also apply to |
|
@valhead What do you think about pseudo-elements? |
|
Two additional note on the
Applying the rule to Related to your button hover example, @jensimmons : It looks like a Adjusting for not allowing infinitely repeating animations and the fact that only keyframe animations appear to fail with the |
|
For animation, what if the duration was set to a really large value instead of a really small value to effectively pause it? On that note, @media (prefers-reduced-motion: reduce) {
* {
animation-play-state: paused !important;
transition: none !important;
}
}
This still may run into the case of animations that start by hiding content through |
|
Thoughts on this? I’m liking @valhead’s direction but modified with a delay to fast forward the animation. @media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-delay: -1s !important;
animation-duration: 1s !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01s !important;
}
}example here: https://codepen.io/scottkellum/pen/YogBVM?editors=1100 |
|
In addition to animations and transitions, I too, think the impact of Also, here's an opinion on parallax motion effect due to
So perhaps: |
|
Was there an explicit decision made not to include |
Add scroll-behavior auto to rerduced-motion see #11
As I understand it, the negative Also I noticed there's no |
|
If you have to choose the lesser of two evils; you can make a significantly less evil, lesser evil: *, ::before, ::after {
animation-delay: -1ms !important;
animation-duration: 1ms !important;
...
}That should still produce a net |
Following the best practices for `prefers-reduced-motion` that were the outcome of a discussion in jensimmons/cssremedy#11, via #1849 (comment). Thanks, @Malvoz.
|
@rjgotten I agree. @mirisuzanne do you mind checking out #11 (comment), and #11 (comment)? Thanks! |
|
@Malvoz That all makes sense to me. Do you want to open a PR? |
Changes motivated by jensimmons#11 (comment), and jensimmons#11 (comment). Thanks @rjgotten
…Via https://larlet.fr/david/ (seen in its CSS), thank's David ;-) — Source: jensimmons/cssremedy#11
|
This has already been included in the PR above, but for those looking at this thread, make sure to also zero out the transition delay. |
I wrote
Or I should say, I snagged that code from discussions on Twitter. Which I'd linked to, but then erased the link. Hm, I should find it again.
@meyerweb raised a good point — why 0.1s and not 0?
Also, do browsers not do this already? Is there no mandate in the CSS spec for user agents to enforce this? Why not? Or if there is (and browsers just haven't implemented it yet), then what is it? What was the discussion about this?
Likely there's some back story with wisdom we can draw from.
The text was updated successfully, but these errors were encountered: