HSNCRC.
TRTell Me About Your Project

Services

  1. Blog
  2. Web Development

An Interface Experiment: Three Dimensions With CSS

A rotating 3D showcase does not require video or WebGL; five ordinary HTML boxes are enough. All of the boxes contain real text, search engines can read them, and screen readers can reach them. What gives the third dimension is three CSS properties.

Three Core Properties

  • perspective: Gives the scene depth. As the value gets smaller, the camera moves closer and the distortion increases.
  • transform-style: preserve-3d: Lets child elements keep their own 3D positions. Without it, everything sticks to a flat surface.
  • backface-visibility: hidden: Hides the faces that are turned away.

HTML

<div class="sahne">
  <div class="prizma" style="--i: 0">
    <article class="yuz" style="--n: 0">Search</article>
    <article class="yuz" style="--n: 1">AI</article>
    <article class="yuz" style="--n: 2">Social media</article>
    <article class="yuz" style="--n: 3">Website</article>
    <article class="yuz" style="--n: 4">Automation</article>
  </div>
</div>

--n holds the order of each face, and --i holds which face the prism is showing at that moment.

Calculating The Radius

In a five-sided prism, each face is rotated 360 / 5 = 72 degrees relative to the previous one. For the edges of the faces to meet exactly, you need to know how far from the center they should be pushed:

radius = width / (2 × tan(180° / number of faces))
       = width / (2 × tan(36°))
       ≈ width × 0.6882

For a four-sided cube this ratio is 0.5; for six sides it is 0.866.

CSS

.sahne {
  --w: 360px;                      /* face width */
  --r: calc(var(--w) * 0.6882);    /* radius */
  perspective: 1300px;
  display: grid;
  place-items: center;
}

.prizma {
  position: relative;
  width: var(--w);
  height: calc(var(--w) * 1.25);
  transform-style: preserve-3d;
  /* Pull back first, then rotate according to the active face */
  transform: translateZ(calc(var(--r) * -1))
             rotateY(calc(var(--i) * -72deg));
  transition: transform 1.1s cubic-bezier(0.25, 0.9, 0.2, 1);
}

.yuz {
  position: absolute;
  inset: 0;
  background: #fff;
  border-radius: 24px;
  backface-visibility: hidden;
  /* Rotate to its own angle, then push outward */
  transform: rotateY(calc(var(--n) * 72deg))
             translateZ(var(--r));
}

The order matters: rotateY must come first, translateZ after it. Because you rotate first, the “forward” direction is rotated too, and each face is pushed in the direction it faces.

The translateZ(-r) on the prism itself brings the front face back exactly onto the screen plane. If you skip this, the front face grows toward you and the text becomes blurry.

JavaScript: Turning It

All that is left is to change the --i value:

const prizma = document.querySelector('.prizma');
const N = 5;
let tur = 0;

function goster(hedef) {
  const simdiki = ((tur % N) + N) % N;
  let fark = (hedef - simdiki + N) % N;
  if (fark > N / 2) fark -= N; // turn the short way around
  tur += fark;
  prizma.style.setProperty('--i', tur);
}

setInterval(() => goster((tur + 1) % N), 4000);

Notice that I do not take the modulo of the tur variable. If the --i value drops from 4 to 0 when moving from face 4 to face 0, the prism makes almost a full turn backward. If you set the value to 5, it reaches the same face in a single step forward.

Accessibility And Performance

  • Motion sensitivity. Under the prefers-reduced-motion: reduce preference, turn off the automatic rotation and bring the transition duration close to zero.
  • Focus. Give the inert attribute to the faces that are not visible; otherwise a user navigating by keyboard gets caught on the links at the back.
  • Performance. If you animate only transform and opacity, the work is done on the graphics card and the page stays smooth. Avoid animating shadows and blur filters.

The result: no library, no extra weight. If I had built the same effect with a 3D engine, I would have had to add hundreds of kilobytes of JavaScript to the page and hide the content from search engines.

Would You Like Help With Corporate Website?

A website that presents your brand accurately and is easy to use on mobile.

Let’s Talk About What You Have In Mind.

A new website, better organized digital communication, or an idea you want to develop… We can work out where to start together.

Tell Me About Your ProjectWhatsApp