AI CSS Animations

Prism Dispersion Text

Red, green and blue copies of the word orbit a hair apart on a dark card, so color fringes circle the white letters. Screen blending adds them back to white, and cos() and sin() place each copy.

Also known as: chromatic aberration text css, rgb split text animation, prism text effect.

Refract

HTML

<div class="txt-prism-dispersion-text"><span class="txt-prism-dispersion-text-base">Refract</span><span aria-hidden="true" style="--k: 0deg">Refract</span><span aria-hidden="true" style="--k: 120deg">Refract</span><span aria-hidden="true" style="--k: 240deg">Refract</span></div>

CSS

@property --txt-prism-dispersion-text-a {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}
@property --txt-prism-dispersion-text-s {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}
.txt-prism-dispersion-text {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 2.2);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.2;
  display: inline-grid;
  isolation: isolate;
  padding: 0.28em 0.6em 0.32em;
  border-radius: 0.32em;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(120% 140% at 50% 0%, color-mix(in srgb, var(--c) 22%, transparent), transparent 60%),
    #09090c;
  box-shadow: 0 0.3em 0.8em -0.3em rgba(0, 0, 0, 0.5);
  color: transparent;
  letter-spacing: -0.02em;
  animation:
    txt-prism-dispersion-text-turn 6s linear infinite,
    txt-prism-dispersion-text-spread 3s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;}
.txt-prism-dispersion-text span {
  grid-area: 1 / 1;
  mix-blend-mode: screen;
  translate:
    calc(cos(var(--txt-prism-dispersion-text-a) + var(--k)) * var(--txt-prism-dispersion-text-s))
    calc(sin(var(--txt-prism-dispersion-text-a) + var(--k)) * var(--txt-prism-dispersion-text-s));
}
.txt-prism-dispersion-text span:nth-child(2) { color: #ff2020; }
.txt-prism-dispersion-text span:nth-child(3) { color: #20ff20; }
.txt-prism-dispersion-text span:nth-child(4) { color: #2020ff; }
.txt-prism-dispersion-text .txt-prism-dispersion-text-base { translate: none; }
@keyframes txt-prism-dispersion-text-turn {
  to { --txt-prism-dispersion-text-a: 360deg; }
}
@keyframes txt-prism-dispersion-text-spread {
  0%, 15% { --txt-prism-dispersion-text-s: 0.012em; }
  100%    { --txt-prism-dispersion-text-s: 0.048em; }
}
@media (prefers-reduced-motion: reduce) {
  .txt-prism-dispersion-text { animation: none; --txt-prism-dispersion-text-a: 200deg; --txt-prism-dispersion-text-s: 0.04em; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-prism-dispersion-text, .txt-prism-dispersion-text *, .txt-prism-dispersion-text::before, .txt-prism-dispersion-text::after, .txt-prism-dispersion-text *::before, .txt-prism-dispersion-text *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations