AI CSS Animations

Image Zoom Card

The cover image scales up inside its frame while the frame stays put, a cinematic push-in. The image container clips the overflow so nothing spills.

Also known as: image hover zoom, zoom on hover, ken burns hover.

Weekend in Lisbon

Three days of tiles, tarts and trams.

HTML

<article class="hfx-card-image-zoom">
  <div class="hfx-card-image-zoom-image"></div>
  <div class="hfx-card-image-zoom-body">
    <h3>Weekend in Lisbon</h3>
    <p>Three days of tiles, tarts and trams.</p>
  </div>
</article>

CSS

.hfx-card-image-zoom {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  width: 15em;
  border-radius: 0.75em;
  overflow: hidden;
  background: #fff;
  border: 1px solid color-mix(in srgb, #000 10%, transparent);
  color: #1f2937;
  font-family: system-ui, sans-serif;
}
.hfx-card-image-zoom-image {
  height: 7em;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 45%, #fff), var(--c));
  transition: transform 0.5s ease;
}
.hfx-card-image-zoom:hover .hfx-card-image-zoom-image {
  transform: scale(1.12);
}
.hfx-card-image-zoom-body {
  padding: 0.9em 1em 1.1em;
}
.hfx-card-image-zoom h3 {
  margin: 0 0 0.25em;
  font-size: 1.05em;
}
.hfx-card-image-zoom p {
  margin: 0;
  font-size: 0.85em;
  color: #6b7280;
  line-height: 1.4;
}

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

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<article class="group w-60 overflow-hidden rounded-xl border bg-white">
  <div class="h-28 overflow-hidden">
    <div class="h-full bg-gradient-to-br from-blue-300 to-blue-500 transition-transform duration-500 group-hover:scale-110"></div>
  </div>
  <div class="p-4">
    <h3 class="font-semibold">Weekend in Lisbon</h3>
    <p class="text-sm text-gray-500">Three days of tiles, tarts and trams.</p>
  </div>
</article>

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