An interactive guide to CSS transitions
joshwcomeau.com
joshwcomeau.com
Properties like background-color are not expensive to animate, the same cost as properties like transform and opacity.
The “curious little imperfection” of text rendering changing slightly simply doesn’t occur.
will-change is obsolete, effectively becoming a noop.
Properties like margin-top and top can animate just as smoothly as a transleY transformation. (And it will be calculated subpixelly, though Firefox deliberately still snaps both to pixels, yet a little differently for nuanced layout reasons; so there can still be a very subtle difference between the two, and it’s definitely browser-dependent. But most of the rendering difference between the two in non-Firefox browsers is categorically a bug, not a feature.)
It would be good to get all of this mentioned. There are a couple of other related simple factual errors, such as “One is done using margin-top, so it can't be hardware accelerated.”—margin-top can be as hardware accelerated as everything else.
But this is my only quibble with the article at this time. The rest is excellent. I was even getting near the end, worried that hover infinite loops wouldn’t be mentioned, but the doom flicker is there. Good stuff.
Interesting, I always thought that because margin changes the layout it triggers the associated recalculations thus is slower than translate which doesn't
The consequence is in many cases the cost of layout is still negligible, and it can keep going smoothly.
The situation on animating things like margin-top and height is pretty much this: (a) under the old regime, jank was pretty much guaranteed; (b) in Servo, it’s actually pretty hard to cause jank—you’ve got to have a significant number of layers, many more than the typical page will have; (c) Firefox is in between, that if your layers aren’t too complex you will probably avoid jank.
(Please note that I’m not encouraging animating layout-affecting properties needlessly; you should almost certainly animate a transformation instead, because it requires strictly less work to be done. But on the other hand, if you have `position: absolute`, it’s cool to know that adjusting `top` (with unconstrained `bottom`) will perform as well as a translateY transformation under WebRender.)
I had a side project that I was desperate to get across a finish line, and I rarely do any CSS at a day job, so I hired a freelancer just to help me get a few CSS issues fixed. One of the things he did was add a few CSS transitions, and the smallest transitions can turn a boring, static site into feeling slick and modern. Simple things like just having elements fade in a little when they appear make a huge visual difference.
As someone who's very far from a talented designer, I realized, transitions are such great value. You can learn a few CSS transition tricks and elevate the perceived design skill of your project greatly relative to the effort spent on learning them.
I'll be using this!
Animations regardless of the domain should be used extremely sparingly. It’s appalling that JS frameworks such as Svelte has this built in. It’s only going to encourage more animations.
I can only imaging how much faster macOS would feel if for example exposè had no animation. Forget about better processors and GPU, the easiest way to make the entire OS faster by 500% would be to turn off all animations. Unfortunately, Apple doesn’t allow us. Even accessibility settings for “reduce motion” just uses fade-in/out animation instead. I really don’t buy the arguments for animation “it gives context to where things come from and where they pop out”. I find that disputable, sure good for initial familiarity but painful the second time.
[1] https://osxdaily.com/2012/02/14/speed-up-misson-control-anim...
Agreed. I once heard the expression "animations should be felt, not seen." This really resonated with me. For example, dialing the transition time down to 30ms gives the user the experience of something vanishing or the color immediately changing, but the effect is to soften what is otherwise the jerky immediacy of computers.
Of COURSE they add the fancy scene or slide transitions. (at first)
and then you learn that you should just cut.
Similarly, why are experienced designers adding transitions to their site that people wouldn't add in their second or third site build?
Apple's big strength is to make people feel safe and welcome in their ecosystem, and they target people who are willing to pay more for that experience.
Apparently, in MacOS, reduced motion is just the same except it’s a fade animation. More importantly, it takes the same amount of time.
Turning them off entirely is an option but in my experience that can produce a few confusing results. It's livable, though.
I think a second part or another thing to talk about that is often missed is weirdness with nested element transitions and inherited transitions on elements. Can be a bit to wrangle for beginners and get to feel smooth.
Besides that, thanks for the resource. I will point this to many!
I’ll be referring back to this.
When he has time and feels ready, he should write an article about how to plan and write explanatory articles. People in many fields could learn from him.
This is a Chrome-case, Firefox (on Windows) aligns both cases to the pixel grid.
Enjoy how you break down what's happening and also throw in some "fun facts" of the reasons why something came to be.
Like the will-transform property, have always used it but didn't realize it came out of people hacking the transform3D property to get GPU acceleration
Ps....The subscribe cta button has one of the nicest designs I have ever seen, wow.
Initially I tried react-spring, but couldn't get it work its transition without triggering rendering of the enclosing component way too many times, and what baffled me nondeterministically. I tried to minimize the problem but it just seemed to be part of it. (native attribute didn't work even with animated.div wrapper). Otherwise seemed like a nice animation package.
Ended up using (previously?) official react-transition-group and voila it worked very nicely with a list of tens of items.
Animation can make the UI much more easy to grok for the user.
"display: none;" if you do
though as with all things CSS, tends to be a bit easier said than done
(this is sort of a wild shot in the dark guessing at what you're talking about, but I've done a lot of CSS and it feels like a good guess)
.btn { will-change: transform; }
thanks, man that was annoying.