AI CSS Animations

Ken Burns Image Hover

Hovering starts a slow documentary-style push and pan across the photo while letterbox bars slide in. The hover transition runs 8 seconds, the exit only 0.8, so it never feels stuck.

Also known as: slow zoom pan hover, cinematic image hover, ken burns effect css.

HTML

<figure class="hfx-image-ken-burns">
  <div class="hfx-image-ken-burns-photo" role="img" aria-label="Valley at dusk"></div>
</figure>

CSS

.hfx-image-ken-burns {
  --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-ken-burns-photo {
  position: absolute;
  inset: 0;
  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%);
  transform-origin: 70% 40%;
  transition: transform 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}
.hfx-image-ken-burns::before,
.hfx-image-ken-burns::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  height: 0.9em;
  background: #05060f;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-image-ken-burns::before {
  top: 0;
  transform: translateY(-100%);
}
.hfx-image-ken-burns::after {
  bottom: 0;
  transform: translateY(100%);
}
.hfx-image-ken-burns:hover .hfx-image-ken-burns-photo {
  transform: scale(1.3) translate(-4%, 2%);
  transition: transform 8s cubic-bezier(0.2, 0, 0.3, 1);
}
.hfx-image-ken-burns:hover::before,
.hfx-image-ken-burns:hover::after {
  transform: none;
}

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