AI CSS Animations

Ambient Glow Image Hover

The photo lifts and casts a soft glow in its own colors, like ambient TV lighting. The glow is a blurred, saturated copy of the same background sitting behind it, faded in with opacity.

Also known as: colored shadow image, blurred image shadow, ambilight hover effect.

HTML

<div class="hfx-image-ambient-glow">
  <div class="hfx-image-ambient-glow-photo" role="img" aria-label="Mountains at dusk"></div>
</div>

CSS

.hfx-image-ambient-glow {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  isolation: isolate;
  width: 13em;
  height: 8em;
}
.hfx-image-ambient-glow::before,
.hfx-image-ambient-glow-photo {
  border-radius: 0.75em;
  background:
    radial-gradient(70% 40% at 16% 110%, color-mix(in srgb, var(--c) 18%, #0b0a1f) 99%, transparent),
    radial-gradient(66% 38% at 88% 108%, color-mix(in srgb, var(--c) 24%, #0b0a1f) 99%, transparent),
    conic-gradient(from 128deg at 68% 44%, transparent 0, color-mix(in srgb, var(--c) 32%, #1e1b4b) 0.4deg 103.6deg, transparent 104deg),
    conic-gradient(from 119deg at 90% 52%, transparent 0, color-mix(in srgb, var(--c) 32%, #1e1b4b) 0.4deg 121.6deg, transparent 122deg),
    conic-gradient(from 123deg at 24% 40%, transparent 0, color-mix(in srgb, var(--c) 42%, #6b2159) 0.4deg 113.6deg, transparent 114deg),
    conic-gradient(from 125deg at 46% 54%, transparent 0, color-mix(in srgb, var(--c) 42%, #6b2159) 0.4deg 109.6deg, transparent 110deg),
    radial-gradient(circle at 38% 58%, #fef3c7 0 1em, rgb(254 215 170 / 0.55) 1.1em, transparent 4.2em),
    linear-gradient(color-mix(in srgb, var(--c) 58%, #1e1b4b), color-mix(in srgb, var(--c) 34%, #f472b6) 52%, color-mix(in srgb, var(--c) 12%, #fdba74) 76%);
}
.hfx-image-ambient-glow::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0.5em;
  filter: blur(0.9em) saturate(1.8);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.45s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-ambient-glow-photo {
  height: 100%;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-ambient-glow:hover::before {
  opacity: 0.9;
  transform: translateY(0.6em);
}
.hfx-image-ambient-glow:hover .hfx-image-ambient-glow-photo {
  transform: translateY(-0.3em);
}

@media (prefers-reduced-motion: reduce) {
  .hfx-image-ambient-glow, .hfx-image-ambient-glow *, .hfx-image-ambient-glow::before, .hfx-image-ambient-glow::after, .hfx-image-ambient-glow *::before, .hfx-image-ambient-glow *::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