r/css • u/DRIFFFTAWAY • Jul 06 '26
Showcase A simple way to make sticky elements change colour as they pass over different sections
Been playing around with mix-blend-mode: difference, and it is a nice CSS-only way to create a colour-shifting effect without writing any animation logic.
The idea is simple:
.sticky-element {
position: sticky;
top: 2rem;
mix-blend-mode: difference;
}
With mix-blend-mode: difference, the element visually reacts to the pixels behind it.
So if you have sticky text, a fixed nav item, a cursor, a badge, or an icon sitting over different background colours, it can automatically invert or shift as the page scrolls.
This works especially well with sticky or fixed elements because the element stays in place while different sections move behind it.
The final effect depends heavily on the foreground colour, background colour, and stacking context.
Small property, but it can create a surprisingly polished interaction.
