Good writeup by Katherine Kato of several techniques on how to change the color of a link on hover, animated
Let’s create a pure CSS effect that changes the color of a text link on hover… but slide that new color in instead of simply swapping colors.
There are four different techniques we can use to do this. Let’s look at those while being mindful of important things, like accessibility, performance, and browser support in mind.
When looking only at the code, I’m more a fan of the
background-clip: text technique as it does not require you to duplicate the text into a
data-* attribute. It does however has some nasty side-effects such as no longer displaying text-decorations and shadows.
If we only had something like
content: text-content; in CSS, then we could remove the
data-* content duplication requirement.
💄 Apart from animating only color, I also like animating the separate
text-decoration-* properties or
background-size on hover.