AI CSS Animations

Refracting Glass Text

Clear glass letters over a slow, glowing color field that bends slightly as it passes through them. The same blurred blobs are clipped to the text a little larger, under a gloss and a bright rim.

Also known as: glass text effect css, refraction text effect, glass letters css, lens text effect.

Refract

HTML

<div class="txt-refracting-glass-text"><span class="txt-refracting-glass-text-word">Refract</span></div>

CSS

.txt-refracting-glass-text {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 1.8);
  font-family: system-ui, sans-serif;
  font-weight: 900;
  line-height: 1.2;
  --blobs:
    radial-gradient(closest-side, var(--c), transparent),
    radial-gradient(closest-side, color-mix(in srgb, var(--c) 30%, #ec4899), transparent),
    radial-gradient(closest-side, color-mix(in srgb, var(--c) 20%, #f59e0b), transparent);
  display: inline-block;
  overflow: hidden;
  border-radius: 0.35em;
  background: var(--blobs), #0c1020;
  background-size: 65% 170%, 60% 160%, 50% 150%, auto;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08), 0 0.35em 0.9em -0.35em rgb(15 23 42 / 0.5);
  letter-spacing: 0.01em;
  animation: txt-refracting-glass-text-drift 8s ease-in-out infinite alternate;}
/* The word fills the card, so its copy of the field lines up with the one
   behind it; the slightly larger blobs are the refraction. */
.txt-refracting-glass-text-word {
  display: block;
  padding: 0.25em 0.65em;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.75), rgb(255 255 255 / 0.2) 45%, rgb(255 255 255 / 0.12) 80%, rgb(255 255 255 / 0.45)),
    var(--blobs),
    #59628c;
  background-size: 100% 100%, 75% 190%, 70% 180%, 60% 170%, auto;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 0.01em rgb(255 255 255 / 0.95)) drop-shadow(0 0 0.01em rgb(255 255 255 / 0.6)) drop-shadow(0 0.05em 0.06em rgb(0 0 0 / 0.5));
  animation: txt-refracting-glass-text-bend 8s ease-in-out infinite alternate;
}
@keyframes txt-refracting-glass-text-drift {
  from { background-position: 0% 30%, 100% 80%, 60% 0%, 0 0; }
  to   { background-position: 100% 70%, 0% 20%, 30% 100%, 0 0; }
}
@keyframes txt-refracting-glass-text-bend {
  from { background-position: 0 0, 0% 30%, 100% 80%, 60% 0%, 0 0; }
  to   { background-position: 0 0, 100% 70%, 0% 20%, 30% 100%, 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .txt-refracting-glass-text, .txt-refracting-glass-text-word { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-refracting-glass-text, .txt-refracting-glass-text *, .txt-refracting-glass-text::before, .txt-refracting-glass-text::after, .txt-refracting-glass-text *::before, .txt-refracting-glass-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