Color Shifting in CSS * Josh W. Comeau
Briefly

Color Shifting in CSS * Josh W. Comeau
"This looks alright, but we probably don't want to use completely random colors. It would feel a lot more cohesive if all of our colors had the same general feel (eg. all pastel colors, or all neon colors). It's not at all obvious how we would do this with rgb(), but if we switch to hsl(), things get a lot easier."
"In this tutorial, I'll share what I've learned, and you'll see how to build some super-cool color-shifting effects in CSS! Intended audience This tutorial was written for developers of all experience levels. If you understand the fundamentals of HTML/CSS/JS, you should be able to follow along! I do assume some familiarity with the hsl() color format and CSS keyframe animations, but I also have blog posts about both of those topics, and I'll link them further down as they become relevant."
Particles start with random colors and change hue while fading out, aiming for visually cohesive palettes rather than fully random RGB tones. Random RGB selection can produce 16.7 million colors but lacks easy control over overall character. Using HSL allows randomizing hue while locking saturation and lightness to create cohesive pastel or neon ranges. For example, choosing a random hue but fixing saturation at 100% and lightness at 80% yields pastel-like tones. The approach assumes familiarity with HSL and CSS keyframe animations. A CSS limitation impacts hue-shifting during fade animations, prompting alternative techniques and workarounds to achieve dynamic, per-particle color transitions in pure CSS.
Read at Joshwcomeau
Unable to calculate read time
[
|
]