Seven ways to add depth with CSS: an isometric block, a book with a spine and pages, a note with a folded corner, a headline laid back in perspective, a thick button that presses down, a shaded sphere and a card with a stack of layers behind it.
A card turned into an isometric view with rotateX and rotateZ, with two side faces made from pseudo-elements so it reads as a solid block. Isometric shapes keep parallel lines parallel, which makes them clean for illustrations.
A book standing at an angle with a visible spine and page edges, made from a cover face and pseudo-elements turned 90 degrees in 3D space. Hover turns it to face you, a nice touch for ebook and course pages.
A note card with its top-right corner folded down, giving a paper feel. The fold is a triangle made by a two-colour linear gradient on a pseudo-element, with a small shadow so it lifts off the card.
View code
<article class="d33"><h3>Remember</h3><p>Water the herbs on Thursday.</p></article>
A headline laid back into the distance like a title crawl, using perspective on the parent and rotateX on the text, with a gradient mask fading the far edge. The text stays real and selectable.
View code
<div class="d34"><p>A long time ago, in a design system far, far away, every button had its own shade of blue.</p></div>
A thick button whose side is a solid darker layer underneath, built from an outer element (the side) and an inner face that moves down on press. The face travels most of the depth, so pressing it feels mechanical.
A convincing ball from one element: an off-centre radial gradient for the highlight, a darker edge for the shadow side and an ellipse shadow on the ground. Moving the highlight's position moves the apparent light source.
View code
<div class="d36" role="img" aria-label="A shaded blue sphere"><span class="b"></span><span class="s"></span></div>
A card with two offset copies of itself behind it in lighter shades, like a neat stack of paper. The copies are hard-edged box-shadows with spread, so there are no extra elements and they follow the card's border radius.
Some effects use true 3D transforms with perspective and preserve-3d; others fake depth with gradients and shadows. Faked depth is cheaper and never distorts text.
Light from one direction
Pick a light source, usually top left, and keep every highlight and shadow consistent with it. Mixed light directions make 3D look wrong even when the shapes are right.
Side faces from pseudo-elements
Rotate ::before and ::after 90 degrees from an edge to build the sides of a block or the spine of a book, so one element becomes a solid.
Keep text flat
Text in heavy perspective is hard to read. Use 3D for shapes and decoration, and keep body text facing the reader.
Frequently asked questions
Do 3D transforms work everywhere?
Yes, in all current browsers.
Is 3D bad for performance?
Static 3D transforms are cheap. Animating large 3D scenes needs care on phones.
Should 3D move for reduced motion?
Static depth is fine; turn off animated rotations under prefers-reduced-motion.