3D & Depth
3D effects, spatial depth, parallax and motion path.
Updated
How do you add 3D depth to a web page with CSS?
3D effects give flat interfaces a sense of depth by placing elements in a virtual space. In CSS this relies on the perspective property, transform-style: preserve-3d and 3D transforms such as rotateY() and translateZ(); WebGL takes over when a scene needs real lighting or hundreds of objects.
How to choose, performance and accessibility
- Use CSS 3D for pieces people interact with: Card Flip 3D for a pricing or team card, Perspective Tilt for a product visual, 3D Carousel for a gallery; keep WebGL for immersive heroes.
- Animate only
transformandopacityso the browser can use the GPU, avoid stacking many 3D layers on mobile, and drop large rotations forprefers-reduced-motion. - Rotating Cube, Mouse Parallax Scene and Floating Shadows are free with their full code; the other effects on this page come with Premium.
Real 3D, not CSS perspective
The effects on this page fake depth with CSS. The SVG to 3D generator builds an actual volume: your logo is extruded, lit, it casts a shadow and you can grab it.
The preview and the image are free. The code comes for $4.90 (this generator, unlimited exports) or with lifetime access.
Open the generatorView source code
<div class="fx-0001-root">
<div class="demo-3d">
<div class="cube-container" tabindex="0" role="group" aria-label="3D cube: point at it, or use the arrow keys">
<div class="cube">
<div class="cube-face front">Front</div>
<div class="cube-face back">Back</div>
<div class="cube-face right">Right</div>
<div class="cube-face left">Left</div>
<div class="cube-face top">Top</div>
<div class="cube-face bottom">Bottom</div>
</div>
</div>
</div>
</div>.fx-0001-root,
.fx-0001-root *,
.fx-0001-root *::before,
.fx-0001-root *::after {
box-sizing: border-box
}
.fx-0001-root {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 250px;
overflow: hidden;
position: relative;
background: rgb(26, 26, 36);
color: rgb(255, 255, 255);
font-family: sans-serif;
}
.demo-3d {
width: 280px;
height: 200px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.cube-container {
width: 100px;
height: 100px;
perspective: 600px;
/* A finger turns the cube instead of scrolling the page (100 px area). */
touch-action: none;
outline: none;
}
.cube-container:focus-visible {
outline: 2px solid #a5b4fc;
outline-offset: 22px;
border-radius: 6px;
}
.cube-container:focus-visible .cube-face {
border-color: rgba(255, 255, 255, 0.9);
}
.cube {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transform: rotateX(-20deg) rotateY(-30deg);
transition: transform 0.1s ease-out;
}
.cube-face {
position: absolute;
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 14px;
border: 2px solid rgba(255, 255, 255, 0.3);
backface-visibility: visible;
}
.cube-face.front {
background: rgba(99, 102, 241, 0.8);
transform: translateZ(50px);
}
.cube-face.back {
background: rgba(139, 92, 246, 0.8);
transform: rotateY(180deg) translateZ(50px);
}
.cube-face.right {
background: rgba(217, 70, 239, 0.8);
transform: rotateY(90deg) translateZ(50px);
}
.cube-face.left {
background: rgba(6, 182, 212, 0.8);
transform: rotateY(-90deg) translateZ(50px);
}
.cube-face.top {
background: rgba(16, 185, 129, 0.8);
transform: rotateX(90deg) translateZ(50px);
}
.cube-face.bottom {
background: rgba(244, 63, 94, 0.8);
transform: rotateX(-90deg) translateZ(50px);
}
/* Reduced motion: the cube no longer follows the pointer and stays at its three-quarter pose;
the arrow keys still turn it, in 15° steps, with no transition. */
@media (prefers-reduced-motion: reduce) {
.fx-0001-root .cube { transition: none }
}(function() {
// Rotating Cube: the cube turns toward the pointer (mouse or finger) and goes back to its three-quarter pose when it leaves.
// With the keyboard (Tab), the arrow keys turn it in 15° steps; Escape puts it back at three-quarters.
// One cube per .fx-0001-root: several copies can live on the same page.
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)');
var REST_X = -20, REST_Y = -30;
document.querySelectorAll('.fx-0001-root').forEach(function(root) {
var cube = root.querySelector('.cube');
var zone = root.querySelector('.cube-container');
if (!cube || !zone) return;
var keyX = REST_X, keyY = REST_Y;
function turn(x, y) {
cube.style.transform = 'rotateX(' + x + 'deg) rotateY(' + y + 'deg)';
}
function rest() {
keyX = REST_X;
keyY = REST_Y;
turn(REST_X, REST_Y);
}
function follow(e) {
if (reduce.matches) return; // reduced motion: no tilt following the pointer
var rect = zone.getBoundingClientRect();
var x = e.clientX - rect.left - rect.width / 2;
var y = e.clientY - rect.top - rect.height / 2;
turn(-y / 5, x / 5);
}
zone.addEventListener('pointermove', follow);
zone.addEventListener('pointerdown', follow);
zone.addEventListener('pointerleave', rest);
zone.addEventListener('keydown', function(e) {
if (e.key === 'Escape') { rest(); return; }
var step = { ArrowUp: [15, 0], ArrowDown: [-15, 0], ArrowLeft: [0, -15], ArrowRight: [0, 15] }[e.key];
if (!step) return;
e.preventDefault(); // the arrow keys turn the cube, they do not scroll the page
keyX += step[0];
keyY += step[1];
turn(keyX, keyY);
});
zone.addEventListener('blur', rest);
});
})();Folding Panel
A flap that lifts on hover, keyboard focus or touch to reveal a hidden half.
Effect page →Parallax Depth Layers
Stacked layers with 3D depth effect.
Page Turn Effect
A notebook whose pages turn one after another on hover, keyboard focus or touch.
Effect page →Prism Rotation
Six translucent panels in a hexagonal ring that turn and cross like a lantern.
Effect page →3D Button Press V2
3D button with perspective press effect.
Carousel 3D V2
Circular carousel with 5 rotating elements.
Mouse Parallax Scene
Multi-layered scene (stars, moon, mountains, trees) reacting to cursor at different speeds.
Effect page →View source code
<div class="fx-0021-root">
<div class="parallax-scene" data-parallax-scene>
<div class="parallax-layer" data-depth="0.1">
<div class="parallax-stars">
<span class="parallax-star" style="top:10%;left:15%"></span>
<span class="parallax-star" style="top:20%;left:75%"></span>
<span class="parallax-star" style="top:35%;left:45%"></span>
<span class="parallax-star" style="top:15%;left:90%"></span>
<span class="parallax-star" style="top:50%;left:25%"></span>
<span class="parallax-star" style="top:8%;left:55%"></span>
<span class="parallax-star" style="top:42%;left:80%"></span>
<span class="parallax-star" style="top:28%;left:10%"></span>
</div>
</div>
<div class="parallax-layer" data-depth="0.25" style="display:flex;align-items:flex-start;justify-content:flex-end;padding:60px 90px 0 0;">
<div class="parallax-moon"></div>
</div>
<div class="parallax-layer" data-depth="0.4">
<div class="parallax-mountains">
<div class="parallax-mountain mountain-1"></div>
<div class="parallax-mountain mountain-2"></div>
<div class="parallax-mountain mountain-3"></div>
<div class="parallax-mountain mountain-4"></div>
</div>
</div>
<div class="parallax-layer" data-depth="0.6">
<div class="parallax-trees">
<div class="parallax-tree tree-sm"></div>
<div class="parallax-tree tree-lg"></div>
<div class="parallax-tree tree-md"></div>
<div class="parallax-tree tree-sm"></div>
<div class="parallax-tree tree-lg"></div>
<div class="parallax-tree tree-md"></div>
<div class="parallax-tree tree-sm"></div>
</div>
</div>
</div>
</div>.fx-0021-root,
.fx-0021-root *,
.fx-0021-root *::before,
.fx-0021-root *::after {
box-sizing: border-box
}
.fx-0021-root {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 250px;
overflow: hidden;
position: relative;
background: rgb(26, 26, 36);
color: rgb(255, 255, 255);
font-family: sans-serif;
}
.parallax-scene {
width: 100%;
height: 250px;
position: relative;
overflow: hidden;
border-radius: 12px;
background: linear-gradient(180deg, #0a0a2e 0%, #1a1a4e 50%, #2a1a3e 100%);
cursor: crosshair;
/* Touch: a sideways drag moves the layers, a vertical swipe still scrolls the page */
touch-action: pan-y;
}
.parallax-layer {
position: absolute;
inset: -30px;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.1s ease-out;
will-change: transform;
}
.parallax-stars {
width: 100%;
height: 100%;
}
.parallax-star {
position: absolute;
width: 3px;
height: 3px;
background: white;
border-radius: 50%;
opacity: 0.6;
}
.parallax-moon {
width: 60px;
height: 60px;
background: radial-gradient(circle at 35% 35%, #fef3c7, #fbbf24);
border-radius: 50%;
box-shadow: 0 0 40px rgba(251, 191, 36, 0.4), 0 0 80px rgba(251, 191, 36, 0.2);
}
/* The layers overflow the scene by 30 px on every side: the mountains stand 24 px below
the bottom edge, the trees 6 px below, so both stay visible when the layers move */
.parallax-mountains {
position: absolute;
bottom: 6px;
width: 120%;
left: -10%;
}
.parallax-mountain {
position: absolute;
bottom: 0;
width: 0;
height: 0;
border-style: solid;
}
.mountain-1 {
left: 5%;
border-width: 0 80px 120px 80px;
border-color: transparent transparent #1e1b4b transparent;
}
.mountain-2 {
left: 25%;
border-width: 0 100px 100px 100px;
border-color: transparent transparent #2e1065 transparent;
}
.mountain-3 {
left: 55%;
border-width: 0 90px 130px 90px;
border-color: transparent transparent #1e1b4b transparent;
}
.mountain-4 {
left: 75%;
border-width: 0 70px 90px 70px;
border-color: transparent transparent #2e1065 transparent;
}
.parallax-trees {
position: absolute;
bottom: -40px;
width: 120%;
left: -10%;
display: flex;
justify-content: space-around;
align-items: flex-end;
/* Ground strip under the trees, hidden below the edge at rest: it shows when the trees rise */
padding-bottom: 64px;
background: linear-gradient(to top, #022c22 64px, transparent 64px);
}
.parallax-tree {
width: 0;
height: 0;
border-style: solid;
border-color: transparent transparent #064e3b transparent;
}
.tree-sm {
border-width: 0 12px 40px 12px;
}
.tree-md {
border-width: 0 16px 55px 16px;
}
.tree-lg {
border-width: 0 20px 70px 20px;
}
/* Reduced motion: the landscape stays still in its rest position */
@media (prefers-reduced-motion: reduce) {
.fx-0021-root .parallax-layer {
transform: none !important;
transition: none;
}
}(function() {
// ========== SPATIAL DEPTH ==========
// ==========================================
// 1. Mouse Parallax Scene (pointer events: mouse, pen and touch)
// One instance per .fx-0021-root: several scenes on one page each move on their own.
// ==========================================
document.querySelectorAll('.fx-0021-root').forEach(function(root) {
var scene = root.querySelector('[data-parallax-scene]');
if (!scene) return;
var layers = scene.querySelectorAll('.parallax-layer');
scene.addEventListener('pointermove', function(e) {
var rect = scene.getBoundingClientRect();
var centerX = rect.width / 2;
var centerY = rect.height / 2;
var mouseX = e.clientX - rect.left - centerX;
var mouseY = e.clientY - rect.top - centerY;
layers.forEach(function(layer) {
var depth = parseFloat(layer.getAttribute('data-depth')) || 0.1;
var moveX = mouseX * depth * 0.5;
var moveY = mouseY * depth * 0.5;
layer.style.transform = 'translate(' + moveX + 'px, ' + moveY + 'px)';
});
});
scene.addEventListener('pointerleave', function() {
layers.forEach(function(layer) {
layer.style.transform = 'translate(0, 0)';
});
});
});
})();Depth Card
A card made of four layers (ring, background, text, icon) that spread apart in 3D and pivot on hover.
Effect page →Floating Elements
UI elements floating and oscillating as if weightless with different animation durations.
Effect page →Perspective Scroll
Four panels that come from far away and rush toward the screen in a loop, in pure CSS (perspective and translateZ).
Effect page →Layered Paper
Stack of paper sheets with realistic shadows and slight rotation, spreading out on hover.
Effect page →Isometric Grid
Interactive isometric grid where blocks rise and fall based on cursor proximity.
Effect page →Depth of Field
Three layers, only one in focus: hover, touch or keyboard moves the focus there, a click keeps it.
Effect page →3D Room
Content placed on the floor and walls of a CSS perspective room that turns on drag (mouse or finger) or with the arrow keys and returns to its starting view.
Effect page →Floating Shadows
Three elements resting on their shadows: the mouse acts as the light, and the shadows slide and turn away from it.
Effect page →View source code
<div class="fx-0029-root">
<div class="float-shadow-container" data-float-shadow>
<div class="float-shadow-el">
<div class="float-shadow-shape fs-shape-1">♦</div>
<div class="float-shadow-shadow"></div>
</div>
<div class="float-shadow-el">
<div class="float-shadow-shape fs-shape-2">★</div>
<div class="float-shadow-shadow"></div>
</div>
<div class="float-shadow-el">
<div class="float-shadow-shape fs-shape-3">♥</div>
<div class="float-shadow-shadow"></div>
</div>
</div>
</div>.fx-0029-root,
.fx-0029-root *,
.fx-0029-root *::before,
.fx-0029-root *::after {
box-sizing: border-box
}
.fx-0029-root {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 250px;
overflow: hidden;
position: relative;
background: rgb(26, 26, 36);
color: rgb(255, 255, 255);
font-family: sans-serif;
}
.float-shadow-container {
width: 100%;
height: 250px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: 30px;
cursor: crosshair;
/* Touch: a sideways drag moves the light, a vertical swipe still scrolls the page */
touch-action: pan-y;
}
.float-shadow-el {
position: relative;
transition: transform 0.3s ease;
}
.float-shadow-shape {
width: 60px;
height: 60px;
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
position: relative;
z-index: 2;
}
.fs-shape-1 {
background: linear-gradient(135deg, #6366f1, #818cf8);
}
.fs-shape-2 {
background: linear-gradient(135deg, #ec4899, #f472b6);
border-radius: 50%;
}
.fs-shape-3 {
background: linear-gradient(135deg, #10b981, #34d399);
}
.float-shadow-shadow {
position: absolute;
bottom: -15px;
left: 50%;
transform: translateX(-50%);
width: 50px;
height: 10px;
background: radial-gradient(ellipse, rgba(0, 0, 0, 0.35) 0%, transparent 70%);
border-radius: 50%;
transition: all 0.3s ease;
z-index: 1;
}
/* Reduced motion: the shapes no longer lift; only the shadows follow the light */
@media (prefers-reduced-motion: reduce) {
.fx-0029-root .float-shadow-shape {
transform: none !important;
}
}(function() {
// ==========================================
// 9. Floating Shadows - Dynamic light source (pointer events: mouse, pen and touch)
// One instance per .fx-0029-root: several groups on one page each follow their own light.
// ==========================================
document.querySelectorAll('.fx-0029-root').forEach(function(root) {
var container = root.querySelector('[data-float-shadow]');
if (!container) return;
var elements = container.querySelectorAll('.float-shadow-el');
container.addEventListener('pointermove', function(e) {
var rect = container.getBoundingClientRect();
var mx = e.clientX - rect.left;
var my = e.clientY - rect.top;
var centerX = rect.width / 2;
var centerY = rect.height / 2;
var lightX = (mx - centerX) / centerX;
var lightY = (my - centerY) / centerY;
elements.forEach(function(el) {
var shape = el.querySelector('.float-shadow-shape');
var shadow = el.querySelector('.float-shadow-shadow');
// Move shadow opposite to light direction
var shadowX = -lightX * 15;
var shadowY = lightY * 5 + 5;
var shadowScale = 1 + Math.abs(lightY) * 0.3;
shadow.style.transform = 'translateX(calc(-50% + ' + shadowX + 'px)) scaleX(' + shadowScale + ')';
shadow.style.opacity = 0.6 - Math.abs(lightY) * 0.2;
// Lift shape slightly toward light
shape.style.transform = 'translate(' + (lightX * 3) + 'px, ' + (-Math.abs(lightY) * 5) + 'px)';
// Dynamic box shadow on shape
shape.style.boxShadow = ((-lightX * 8)) + 'px ' + ((-lightY * 8 + 4)) + 'px 20px rgba(0,0,0,0.3)';
});
});
container.addEventListener('pointerleave', function() {
elements.forEach(function(el) {
var shape = el.querySelector('.float-shadow-shape');
var shadow = el.querySelector('.float-shadow-shadow');
shadow.style.transform = 'translateX(-50%)';
shadow.style.opacity = '0.35';
shape.style.transform = 'translate(0, 0)';
shape.style.boxShadow = '';
});
});
});
})();Parallax Tilt Gallery
Image gallery where each element tilts independently based on cursor distance.
Effect page →