You can’t animate gradient colors in CSS. No, really. There are a lot of animatable properties, but the one used for gradients, background-image
, is not on the list.
Fortunately, if you were looking to animate a simple light-to-dark gradient fade, then there’s a decent workaround. Use background-size
to stretch your gradient to be taller than the element it’s on. Now you can animate background-position
to slide the visible portion of your gradient up and down. The end result is an element with a smoothly animated gradient background that gets lighter and darker.
And here’s a demo. Hover over the gray box to see the animation.
Check out this Pen!
Via codersblock.blogspot.com
GIPHY App Key not set. Please check settings