CSS 3D Transforms Without WebGL: Perspective, preserve-3d and the Gotchas

2026-11-17

You do not need WebGL or Three.js to put real depth on a web page. CSS can rotate, move and layer elements in three dimensions on the GPU, with no heavy runtime. It is ideal for cards, carousels, cubes and product showcases. It is not a 3D engine, so it helps to know where it stops. This guide covers the properties that matter and the mistakes that cost people hours.

Perspective: what makes it 3D

Without perspective, a rotated element just looks squashed. perspective on a parent sets how far the viewer is from the scene. A smaller value (400px) gives a dramatic effect, a larger one (1200px) is subtle. The perspective-origin property moves the vanishing point. You can also write perspective(800px) inside a single element's transform, but then every element gets its own vanishing point, which is rarely what you want.

preserve-3d: the property people forget

By default an element flattens its children into its own plane. transform-style: preserve-3d keeps them in 3D space so they can sit in front of and behind each other. It has to be set on every element between the perspective container and the 3D content. One missing link silently flattens everything below it.

<div class="scene">            <!-- perspective: 900px -->
  <div class="cube">            <!-- transform-style: preserve-3d -->
    <div class="face front"></div>
    <div class="face back"></div>
  </div>
</div>
.scene { perspective: 900px; }
.cube  { position: relative; width: 200px; height: 200px;
         transform-style: preserve-3d; animation: spin 12s linear infinite; }
.face  { position: absolute; inset: 0; backface-visibility: hidden; }
.front { transform: translateZ(100px); }
.back  { transform: rotateY(180deg) translateZ(100px); }
@keyframes spin { to { transform: rotateY(360deg); } }

What silently flattens a 3D scene

Several properties force an element to flatten its children, even if you set preserve-3d:

  • overflow set to anything but visible
  • opacity below 1
  • filter, clip-path and mask
  • isolation: isolate and mix-blend-mode

If your cube turns into a flat card, look for one of these on the element or an ancestor. The fix is usually to move the effect to a child that is not part of the 3D chain.

Order of transforms matters

Transforms apply right to left in the order you write them, relative to the element's own, already transformed, axes. rotateY(45deg) translateZ(100px) pushes the element forward and then swings it around the origin, which is how you build the faces of a cube or the items of a carousel. Swap the order and you get a different shape. Setting transform-origin changes the pivot point for all of it.

Keep it fast

  • Animate only transform and opacity. They run on the GPU compositor without layout or paint.
  • Use will-change: transform sparingly, on elements that are actually animating. Putting it on everything wastes memory.
  • Avoid large blurred box-shadow on 3D elements. Fake the shadow with a small gradient element instead.
  • Pause animations that are off screen, and honor prefers-reduced-motion.

When to use WebGL instead

CSS 3D is perfect for a few dozen planes and boxes. Reach for WebGL when you need real lighting, thousands of objects, imported models or shaders. For most interface work, such as hero cards, carousels and product showcases, CSS is lighter, more accessible and easier to style.

See it working

Every Depth UI component is built this way. Open the Cube to see the six-face setup above, the Globe for markers that vanish as they turn away, and the 3D carousel for items placed around a ring. All come with full source you can copy.

Components from this guide