AI CSS Animations

Tile Flip Grid Hover

A night scene split into fifteen tiles that flip in a diagonal wave to show the same view by day. Every tile reads its own slice of one shared background, so both pictures line up.

Also known as: staggered tile flip, mosaic flip reveal, 3d grid flip css.

HTML

<div class="hfx-tile-flip-grid">
  <span style="--x: 0; --y: 0"></span><span style="--x: 1; --y: 0"></span><span style="--x: 2; --y: 0"></span><span style="--x: 3; --y: 0"></span><span style="--x: 4; --y: 0"></span>
  <span style="--x: 0; --y: 1"></span><span style="--x: 1; --y: 1"></span><span style="--x: 2; --y: 1"></span><span style="--x: 3; --y: 1"></span><span style="--x: 4; --y: 1"></span>
  <span style="--x: 0; --y: 2"></span><span style="--x: 1; --y: 2"></span><span style="--x: 2; --y: 2"></span><span style="--x: 3; --y: 2"></span><span style="--x: 4; --y: 2"></span>
</div>

CSS

.hfx-tile-flip-grid {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: grid;
  grid-template-columns: repeat(5, 2.4em);
  grid-auto-rows: 2.4em;
  gap: 0.15em;
  perspective: 40em;
}
.hfx-tile-flip-grid span {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.45, 0, 0.2, 1.15);
  transition-delay: calc((var(--x) + var(--y)) * 0.06s);
}
.hfx-tile-flip-grid span::before,
.hfx-tile-flip-grid span::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0.3em;
  backface-visibility: hidden;
}
.hfx-tile-flip-grid span::before {
  background:
    radial-gradient(circle at 74% 30%, color-mix(in srgb, var(--c) 40%, #0b1120) 0 8%, transparent 8.5%),
    radial-gradient(circle at 70% 32%, #f8fafc 0 9%, transparent 9.5%),
    radial-gradient(circle at 18% 22%, #fff 0 0.8%, transparent 1.2%),
    radial-gradient(circle at 36% 12%, #fff 0 0.6%, transparent 1%),
    radial-gradient(circle at 52% 40%, #fff 0 0.6%, transparent 1%),
    radial-gradient(circle at 90% 12%, #fff 0 0.7%, transparent 1.1%),
    radial-gradient(70% 50% at 25% 100%, color-mix(in srgb, var(--c) 45%, #020617) 99%, transparent),
    radial-gradient(60% 40% at 85% 100%, color-mix(in srgb, var(--c) 30%, #020617) 99%, transparent),
    linear-gradient(color-mix(in srgb, var(--c) 40%, #0b1120), color-mix(in srgb, var(--c) 60%, #1e1b4b));
  background-size: 500% 300%;
  background-position: calc(var(--x) * 25%) calc(var(--y) * 50%);
}
.hfx-tile-flip-grid span::after {
  background:
    radial-gradient(circle at 70% 32%, #fffbeb 0 8%, color-mix(in srgb, #fde047 45%, transparent) 8.5% 13%, transparent 13.5%),
    radial-gradient(70% 50% at 25% 100%, color-mix(in srgb, var(--c) 80%, #000) 99%, transparent),
    radial-gradient(60% 40% at 85% 100%, color-mix(in srgb, var(--c) 60%, #000) 99%, transparent),
    linear-gradient(color-mix(in srgb, var(--c) 20%, #fff), color-mix(in srgb, var(--c) 50%, #fff));
  background-size: 500% 300%;
  background-position: calc(var(--x) * 25%) calc(var(--y) * 50%);
  transform: rotateY(180deg);
}
.hfx-tile-flip-grid:hover span {
  transform: rotateY(180deg);
}

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