AI CSS Animations

Tile Mosaic Image Hover

The photo is secretly nine tiles; hover and they part from the center with a springy stagger into a rounded mosaic. Each tile shows its slice of one background through background-position.

Also known as: image breaks into tiles, grid pieces hover, shatter image effect.

HTML

<div class="hfx-image-tiles" role="img" aria-label="Mountain range">
  <span class="hfx-image-tiles-tile" style="--x: 0; --y: 0; --d: 2"></span>
  <span class="hfx-image-tiles-tile" style="--x: 1; --y: 0; --d: 1"></span>
  <span class="hfx-image-tiles-tile" style="--x: 2; --y: 0; --d: 2"></span>
  <span class="hfx-image-tiles-tile" style="--x: 0; --y: 1; --d: 1"></span>
  <span class="hfx-image-tiles-tile" style="--x: 1; --y: 1; --d: 0"></span>
  <span class="hfx-image-tiles-tile" style="--x: 2; --y: 1; --d: 1"></span>
  <span class="hfx-image-tiles-tile" style="--x: 0; --y: 2; --d: 2"></span>
  <span class="hfx-image-tiles-tile" style="--x: 1; --y: 2; --d: 1"></span>
  <span class="hfx-image-tiles-tile" style="--x: 2; --y: 2; --d: 2"></span>
</div>

CSS

.hfx-image-tiles {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: grid;
  grid-template-columns: repeat(3, 5em);
  grid-template-rows: repeat(3, 3em);
}
.hfx-image-tiles-tile {
  background:
    radial-gradient(74% 44% at 20% 110%, color-mix(in srgb, var(--c) 42%, #0f172a) 99%, transparent),
    radial-gradient(62% 36% at 90% 107%, color-mix(in srgb, var(--c) 56%, #0f172a) 99%, transparent),
    conic-gradient(from 130deg at 72% 40%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 99.6deg, transparent 100deg),
    conic-gradient(from 118deg at 94% 55%, transparent 0, color-mix(in srgb, var(--c) 80%, #1e293b) 0.4deg 123.6deg, transparent 124deg),
    conic-gradient(from 124deg at 30% 36%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 111.6deg, transparent 112deg),
    conic-gradient(from 126deg at 52% 50%, transparent 0, color-mix(in srgb, var(--c) 48%, #fff) 0.4deg 107.6deg, transparent 108deg),
    radial-gradient(circle at 55% 27%, #fff 0 0.85em, rgb(255 255 255 / 0.45) 0.95em, transparent 3.2em),
    linear-gradient(color-mix(in srgb, var(--c) 64%, #fff), color-mix(in srgb, var(--c) 12%, #fff7ed) 72%);
  background-size: 15em 9em;
  background-position: calc(var(--x) * -5em) calc(var(--y) * -3em);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), border-radius 0.4s ease;
  transition-delay: calc(var(--d) * 0.05s);
}
.hfx-image-tiles-tile:nth-child(1) { border-top-left-radius: 0.75em; }
.hfx-image-tiles-tile:nth-child(3) { border-top-right-radius: 0.75em; }
.hfx-image-tiles-tile:nth-child(7) { border-bottom-left-radius: 0.75em; }
.hfx-image-tiles-tile:nth-child(9) { border-bottom-right-radius: 0.75em; }
.hfx-image-tiles:hover .hfx-image-tiles-tile {
  border-radius: 0.4em;
  transform: translate(calc((var(--x) - 1) * 0.5em), calc((var(--y) - 1) * 0.5em)) scale(0.94);
}

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