AI CSS Animations

Blur to Focus Image Hover

A soft, out of focus photo snaps sharp on hover while camera autofocus brackets close in and fade, like a focus pull. The blur is a filter transition, the brackets are background gradients.

Also known as: blur on hover image, unblur image hover, focus pull effect.

HTML

<figure class="hfx-image-blur-focus">
  <div class="hfx-image-blur-focus-photo" role="img" aria-label="Sunset over the sea"></div>
  <span class="hfx-image-blur-focus-af" aria-hidden="true"></span>
</figure>

CSS

.hfx-image-blur-focus {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  width: 15em;
  height: 9.5em;
  margin: 0;
  border-radius: 0.75em;
  overflow: hidden;
}
.hfx-image-blur-focus-photo {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(9% 30% at 50% 74%, rgb(255 255 255 / 0.55), transparent),
    linear-gradient(transparent 62%, color-mix(in srgb, var(--c) 78%, #0f172a) 62%, color-mix(in srgb, var(--c) 62%, #0f172a) 74%, color-mix(in srgb, var(--c) 40%, #020617)),
    radial-gradient(34% 16% at 6% 63%, color-mix(in srgb, var(--c) 36%, #0f172a) 99%, transparent),
    radial-gradient(20% 9% at 92% 62%, color-mix(in srgb, var(--c) 48%, #1e293b) 99%, transparent),
    radial-gradient(circle at 50% 50%, #fffbeb 0 0.9em, rgb(254 243 199 / 0.5) 1em, transparent 3.6em),
    linear-gradient(color-mix(in srgb, var(--c) 56%, #fff), color-mix(in srgb, var(--c) 18%, #fed7aa) 62%);
  filter: blur(0.3em) saturate(0.8);
  transform: scale(1.1);
  transition: filter 0.5s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-blur-focus-af {
  --arm: 0.7em;
  --line: 0.14em;
  position: absolute;
  inset: 0;
  width: 4.4em;
  height: 2.8em;
  margin: auto;
  background:
    linear-gradient(#fff 0 0) 0 0 / var(--arm) var(--line),
    linear-gradient(#fff 0 0) 0 0 / var(--line) var(--arm),
    linear-gradient(#fff 0 0) 100% 0 / var(--arm) var(--line),
    linear-gradient(#fff 0 0) 100% 0 / var(--line) var(--arm),
    linear-gradient(#fff 0 0) 0 100% / var(--arm) var(--line),
    linear-gradient(#fff 0 0) 0 100% / var(--line) var(--arm),
    linear-gradient(#fff 0 0) 100% 100% / var(--arm) var(--line),
    linear-gradient(#fff 0 0) 100% 100% / var(--line) var(--arm);
  background-repeat: no-repeat;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}
.hfx-image-blur-focus:hover .hfx-image-blur-focus-photo {
  filter: none;
  transform: none;
}
.hfx-image-blur-focus:hover .hfx-image-blur-focus-af {
  transform: scale(0.75);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease 0.35s;
}

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