AI CSS Animations

Zoom with Dark Overlay Image

The image pushes in while a dark tint settles over it and a label appears in the middle. The go-to hover for photo grids that lead to a detail page.

Also known as: image dim hover, overlay on hover.

View

HTML

<div class="hfx-image-overlay-zoom">
  <div class="hfx-image-overlay-zoom-image"></div>
  <span>View</span>
</div>

CSS

.hfx-image-overlay-zoom {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  width: 12em;
  aspect-ratio: 4 / 3;
  border-radius: 0.75em;
  overflow: hidden;
  display: grid;
  place-items: center;
  font: 600 1em system-ui, sans-serif;
}
.hfx-image-overlay-zoom-image {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 45%, #fff), var(--c));
  transition: transform 0.5s ease, filter 0.5s ease;
}
.hfx-image-overlay-zoom span {
  position: relative;
  color: #fff;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(0.4em);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.hfx-image-overlay-zoom:hover .hfx-image-overlay-zoom-image {
  transform: scale(1.1);
  filter: brightness(0.55);
}
.hfx-image-overlay-zoom:hover span {
  opacity: 1;
  transform: translateY(0);
}

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