AI CSS Animations

Reflection Text Hover

A tinted reflection fades in under the word and sways gently, like the word is standing at the edge of water. The reflection is a flipped copy with a gradient mask-image.

Also known as: mirror text on hover, text reflection css, water reflection text.

Mirror

HTML

<div class="hfx-text-reflection" data-text="Mirror">Mirror</div>

CSS

.hfx-text-reflection {
  --c: var(--hfx-color, #3b82f6);
  font-size: calc(var(--hfx-size, 16px) * 2.5);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.15;
  cursor: default;
  position: relative;
  display: inline-block;}
.hfx-text-reflection::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 0.44em);
  color: var(--c);
  opacity: 0;
  transform: scaleY(-1);
  -webkit-mask-image: linear-gradient(transparent 25%, rgba(0, 0, 0, 0.55));
  mask-image: linear-gradient(transparent 25%, rgba(0, 0, 0, 0.55));
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.hfx-text-reflection:hover::after {
  opacity: 1;
  animation: hfx-text-reflection-sway 2.4s ease-in-out infinite;
}
@keyframes hfx-text-reflection-sway {
  0%, 100% { transform: scaleY(-1) skewX(0); }
  25%      { transform: scaleY(-0.94) skewX(6deg); }
  75%      { transform: scaleY(-1.04) skewX(-6deg); }
}

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

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 hover effects