A narrow band of spectrum light passes through otherwise plain text, then the line rests. One oklch gradient clipped to the text, with currentColor at both ends so it suits light and dark pages.
Also known as: rainbow text css, subtle rainbow text animation, prism light text effect.
<div class="txt-spectral-sweep-text">Made of light</div>
.txt-spectral-sweep-text {
--c: var(--txt-color, #3b82f6);
font-size: calc(var(--txt-size, 32px) * 1.7);
font-family: system-ui, sans-serif;
font-weight: 800;
line-height: 1.2;
display: inline-block;
letter-spacing: -0.02em;
white-space: nowrap;
/* the fill is transparent but color stays, so currentColor still means the page's text color */
background: linear-gradient(100deg,
currentColor 40%,
oklch(0.66 0.2 25) 44%,
oklch(0.78 0.16 75) 47.5%,
oklch(0.72 0.18 150) 51%,
oklch(0.68 0.15 225) 54.5%,
oklch(0.6 0.21 290) 58%,
currentColor 62%) 100% 0 / 400% 100%;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
animation: txt-spectral-sweep-text-pass 6s cubic-bezier(0.45, 0, 0.3, 1) infinite;}
@keyframes txt-spectral-sweep-text-pass {
0% { background-position: 100% 0; }
72%, 100% { background-position: 0% 0; }
}
@media (prefers-reduced-motion: reduce) {
.txt-spectral-sweep-text { animation: none; background-position: 50% 0; }
}
@media (prefers-reduced-motion: reduce) {
.txt-spectral-sweep-text, .txt-spectral-sweep-text *, .txt-spectral-sweep-text::before, .txt-spectral-sweep-text::after, .txt-spectral-sweep-text *::before, .txt-spectral-sweep-text *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.