AI CSS Animations

3D Carousel Ring Hover

Six picture cards stand in a ring seen slightly from above. Hover and the ring spreads out and spins; leave and it stops where it is, because hover only toggles animation-play-state.

Also known as: css 3d carousel, rotating gallery ring, spinning cards hover.

HTML

<div class="hfx-carousel-ring-3d">
  <div class="hfx-carousel-ring-3d-ring">
    <span style="--i: 0"></span>
    <span style="--i: 1"></span>
    <span style="--i: 2"></span>
    <span style="--i: 3"></span>
    <span style="--i: 4"></span>
    <span style="--i: 5"></span>
  </div>
</div>

CSS

.hfx-carousel-ring-3d {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: grid;
  place-items: center;
  width: 16em;
  height: 10em;
  perspective: 28em;
}
.hfx-carousel-ring-3d-ring {
  position: relative;
  width: 3.6em;
  height: 4.6em;
  transform-style: preserve-3d;
  transform: rotateX(-14deg) rotateY(0deg);
  animation: hfx-carousel-ring-3d-spin 14s linear infinite paused;
}
.hfx-carousel-ring-3d-ring span {
  position: absolute;
  inset: 0;
  border-radius: 0.4em;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 25%, transparent);
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transform: rotateY(calc(var(--i) * 60deg)) translateZ(4.1em);
  transition: transform 0.6s cubic-bezier(0.3, 1.3, 0.5, 1);
}
.hfx-carousel-ring-3d-ring span::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: color-mix(in srgb, var(--c) 45%, #0f172a);
  backface-visibility: hidden;
  transform: rotateY(180deg);
}
.hfx-carousel-ring-3d-ring span:nth-child(1) {
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 30%, #fff), var(--c));
}
.hfx-carousel-ring-3d-ring span:nth-child(2) {
  background: radial-gradient(circle at 50% 35%, #fef3c7 0 0.5em, transparent 0.55em), linear-gradient(color-mix(in srgb, var(--c) 50%, #fb923c), color-mix(in srgb, var(--c) 70%, #000));
}
.hfx-carousel-ring-3d-ring span:nth-child(3) {
  background: repeating-linear-gradient(45deg, var(--c) 0 0.4em, color-mix(in srgb, var(--c) 65%, #fff) 0.4em 0.8em);
}
.hfx-carousel-ring-3d-ring span:nth-child(4) {
  background: radial-gradient(circle at 62% 28%, #f8fafc 0 0.4em, transparent 0.45em), linear-gradient(color-mix(in srgb, var(--c) 40%, #020617), color-mix(in srgb, var(--c) 70%, #0f172a));
}
.hfx-carousel-ring-3d-ring span:nth-child(5) {
  background: linear-gradient(transparent 58%, color-mix(in srgb, var(--c) 75%, #000) 58%), linear-gradient(color-mix(in srgb, var(--c) 20%, #fff), color-mix(in srgb, var(--c) 55%, #fff));
}
.hfx-carousel-ring-3d-ring span:nth-child(6) {
  background: conic-gradient(from 45deg, var(--c), color-mix(in srgb, var(--c) 35%, #fff), var(--c), color-mix(in srgb, var(--c) 60%, #000), var(--c));
}
.hfx-carousel-ring-3d:hover .hfx-carousel-ring-3d-ring {
  animation-play-state: running;
}
.hfx-carousel-ring-3d:hover .hfx-carousel-ring-3d-ring span {
  transform: rotateY(calc(var(--i) * 60deg)) translateZ(5em);
}
@keyframes hfx-carousel-ring-3d-spin {
  to { transform: rotateX(-14deg) rotateY(-360deg); }
}

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