CSS transitions do not have any effect on CSS gradients. As far as I know, the thing is that something similar would be quite difficult to achieve considering the multitude of possible gradients that can be created using a color palette.
Though there are some simple ways you can simulate smooth CSS transitions on gradients and below you’ll see how to do that.
I wrote about this matter in an article on CSS pitfalls and how to overcome them and I was thinking this new article will hopefully be more useful to you as it contains one more extra technique that can help you faking transitions on background gradients.
So, what is this about and why would you care about transitions on gradients? The answer is very simple: just think about the situation when you’re designing some CSS buttons. To make them look awesome, it’s almost mandatory to use shadows, rounded corners and CSS gradients.
Read the workarounds described below and you’ll be able to greatly improve your gradient buttons, especially their
For this demo, we’re using three colored boxes to whom are applied the following workarounds.
I extracted only the important styles needed and as you can see, the
background-color has the most important role, as it’s the one who’s actually being transitioned here.
Having already a transitioned
background-color, you just need to set a semi-transparent background using
background-image and the result will be a smooth gradient transition for the element to whom these styles are applied to.
Perhaps this is a bit dirtier, but it’s still a fully working technique. Instead of a semi-transparent background as above, this assume using an inset CSS box-shadow:
As you can see, the workarounds above are quite simple and easy to implement. Also, the big advantage is that they don’t require any additional markup element to work.
Thanks for reading and feel free to share your thoughts!
Firefox doesn't allow cross-domain fonts
How to create triangle shapes in HTML, SVG & CSS