Copied!
Guide

How to build a 3D carousel in CSS

A ring of cards that turns in space is one rotation per card and one sum for the radius. Here is the sum, the code, and the keyboard support that most carousel demos leave out.

← Blog
Title card: CSS 3D carousel. Preview of the Ring carousel element from the Enrichr Library.

December 4, 2026

3 min readWith the radius formula

To build a 3D ring carousel in CSS, place all the cards on top of each other, turn each one by its share of 360 degrees with rotateY, and push it outward with translateZ. Then rotate the parent to turn the ring. The layout is pure CSS. A few lines of JavaScript step it from card to card.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

What is the code?

<div class="scene">
  <div class="ring" style="--n: 8">
    <div class="card" style="--i: 0">1</div>
    <div class="card" style="--i: 1">2</div>
    <!-- ... up to --i: 7 -->
  </div>
</div>
<button class="prev">Previous</button> <button class="next">Next</button>
.scene { perspective: 1200px; height: 260px; display: grid; place-items: center; }
.ring  {
  --w: 300px;
  --r: calc(var(--w) / 2 / tan(180deg / var(--n)) + 12px);
  position: relative; width: var(--w); height: 200px;
  transform-style: preserve-3d;
  transform: translateZ(calc(var(--r) * -1)) rotateY(calc(var(--step, 0) * -360deg / var(--n)));
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card  {
  position: absolute; inset: 0;
  transform: rotateY(calc(var(--i) * 360deg / var(--n))) translateZ(var(--r));
  backface-visibility: hidden;
}
const ring = document.querySelector(".ring");
let step = 0;
const turn = (d) => ring.style.setProperty("--step", (step += d));

document.querySelector(".next").addEventListener("click", () => turn(1));
document.querySelector(".prev").addEventListener("click", () => turn(-1));
ring.parentElement.tabIndex = 0;
ring.parentElement.addEventListener("keydown", (e) => {
  if (e.key === "ArrowRight") turn(1);
  if (e.key === "ArrowLeft") turn(-1);
});

Where does the radius come from?

The cards form a polygon seen from above. For the edges to touch, the distance from the centre to each card must be (width / 2) / tan(180° / count). CSS now has a tan() function, so the sum can live in the stylesheet and update itself when you change the card count. The ring is also pushed back by the same radius, so the front card sits at its natural size.

Why count steps instead of an angle from 0 to 360?

If you wrap the angle back to 0 after the last card, the ring spins all the way backwards to get there. Letting the step number keep growing means the ring always takes the short way round.

How is coverflow different?

Keep the cards in a flex row. Give the centre card no rotation and a larger scale. Rotate the cards on the left by about 45 degrees and those on the right by minus 45, and pull them a little closer together. Moving to the next card only changes which one counts as the centre.

What does an accessible carousel need?

Which finished examples can I copy?

ElementWhat it does
Ring carouselCards on a CSS 3D ring that rotates one step at a time, with buttons, arrow keys and autoplay.
Image carousel 3DA coverflow row: the centre card flat and enlarged, the others swung away.
Tilted ring carouselA row of photos each turned in 3D by 60 degrees per step, like a ring seen from inside.
Fanned card deckA looping deck of cards fanned like a hand around the one in focus.
Parallax photo carouselA draggable 3D carousel with parallax inner layers, inertia and spring.

All are free in the Enrichr Library. It lists 20 carousels in total.

Where to go next

FAQ

How do I make a 3D carousel with CSS only?

The ring itself is pure CSS: transform-style: preserve-3d on the ring and rotateY() translateZ() on each card. You can spin it with a CSS animation. Stepping to a chosen card needs a little JavaScript.

How do I work out translateZ for a 3D carousel?

Use radius = (cardWidth / 2) / tan(π / count). For 8 cards 300 pixels wide that is about 362 pixels. Add a few pixels for a gap between cards.

Why can I see the backs of the cards?

Cards on the far side of the ring face away from you. Set backface-visibility: hidden to hide them, or leave them visible and dim them for a see-through look.

What is the difference between a ring carousel and coverflow?

In a ring, the cards sit on a circle and the whole circle turns. In coverflow, the cards stay in a row; the centre card faces you and the others are angled away to the sides.