Stuff & Nonsense product and website design

Blog and all that malarkey

A quick note about using filters to change link colours

For as long as I can remember, I’ve been specifying different colours for hyperlinks and their :hover pseudo-classes. Recently, I’ve been experimenting with CSS filters and found they make development much easier.

This is the way I’ve specified link colours for so long:

a {
color: var(--color-text-link); /* #fa6e34 */ }

a:hover {
color: var(--color-text-link-hover); /* #e04606 */ }

Instead of specifying two different colours for hyperlinks and their :hover pseudo-classes, I can use CSS filters including brightness(), hue-rotate(), opacity(), and saturate(). To emulate that darker :hover colour, I might reduce the brightness of a link to 90%:

a:hover {
filter: brightness(90%); }

Or, to brighten a link colour on :hover, I might increase its brightness to 110%:

a:hover {
filter: brightness(110%); }

To change a link colour on :hover to one on the opposite side of the colour wheel—in my case from orange to blue—I can rotate its hue:

a:hover {
filter: hue-rotate(180deg); }

And, to reduce the intensity of previously visited links, I can adjust their saturation using a filter:

a:visited {
filter: saturate(75%); }

I can even add a subtle transition to add depth to the effect. So, my new styles for hyperlinks and pseudo-classes might look like this:

a {
color: var(--color-text-link); /* #fa6e34 */
transition: filter 250ms; }

a:visited {
filter: saturate(75%); }

a:hover {
filter: brightness(110%); }

As I only need to adjust the link colour when a design changes, this approach seems much more flexible than specifying two or more link colours in my stylesheets.


Written by Andy Clarke


More from Stuff & Nonsense

Services I offer

Product UX design

Product UX design

The contract template trusted by thousands of designers and developers to keep their web projects running smoothly.

Design mentorship and teaching

Design mentorship and teaching

Whether you’re stuck, starting out, or stepping up—Andy’s here to help you become a better designer.

Squarespace templates for sale

Squarespace templates for sale

Take your Squarespace designs from good to great with my bespoke templates.

Andy Clarke on YouTube

Andy Clarke on YouTube

Join Andy on YouTube to learn how you can make better product and website designs.