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 with a subscription.
Open the generatorRotating Cube
Interactive 3D cube that follows the mouse movement.
View source code
<div class="demo-preview">
<div class="demo-3d">
<div class="cube-container">
<div class="cube" id="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>.demo-preview,
.demo-preview *,
.demo-preview *::before,
.demo-preview *::after {
box-sizing: border-box
}
.demo-preview {
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;
}
.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);
}(function() {
// 1. Rotating Cube - Mouse interaction
const cube = document.getElementById('cube');
const cubeContainer = cube.parentElement;
cubeContainer.addEventListener('mousemove', (e) => {
const rect = cubeContainer.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
const rotateX = -y / 5;
const rotateY = x / 5;
cube.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
});
cubeContainer.addEventListener('mouseleave', () => {
cube.style.transform = 'rotateX(-20deg) rotateY(-30deg)';
});
})();Card Flip 3D
Full card flip with realistic 3D effect.
Perspective Tilt
Element that tilts in 3D based on cursor position.
3D Carousel
Circular carousel with continuous 3D rotation.
Folding Panel
Panel that unfolds like paper on hover.
3D Button Press
Button with realistic 3D press effect.
Layered Parallax 3D
Multiple layers with 3D depth effect.
Rotating Text
Text with continuous animated 3D rotation.
Isometric Grid
Isometric grid with interactive 3D cubes.
Cube Auto-Rotation
3D cube with continuous automatic rotation.
Parallax Depth Layers
Stacked layers with 3D depth effect.
Fold Effect Card
Card that folds inward on hover.
Door Open Effect
3D door that opens to reveal the content.
Page Turn Effect
Page turning effect on hover.
Prism Rotation
Hexagonal prism with automatic rotation.
Floating Elements 3D
Floating elements with animated 3D rotation.
3D Button Press V2
3D button with perspective press effect.
Carousel 3D V2
Circular carousel with 5 rotating elements.
Shadow Perspective
Card with realistic 3D shadow that reacts on hover.
Mouse Parallax Scene
Multi-layered scene (stars, moon, mountains, trees) reacting to cursor at different speeds.
View source code
<div class="demo-preview">
<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:30px 60px 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>.demo-preview,
.demo-preview *,
.demo-preview *::before,
.demo-preview *::after {
box-sizing: border-box
}
.demo-preview {
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;
}
.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);
}
.parallax-mountains {
position: absolute;
bottom: -30px;
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: -30px;
width: 120%;
left: -10%;
display: flex;
justify-content: space-around;
align-items: flex-end;
}
.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;
}(function() {
// ========== SPATIAL DEPTH ==========
// ==========================================
// 1. Mouse Parallax Scene
// ==========================================
document.querySelectorAll('[data-parallax-scene]').forEach(function(scene) {
var layers = scene.querySelectorAll('.parallax-layer');
scene.addEventListener('mousemove', 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('mouseleave', function() {
layers.forEach(function(layer) {
layer.style.transform = 'translate(0, 0)';
});
});
});
})();Depth Card
Card with layered elements (background, text, icon) separating in 3D on hover with translate3d.
Floating Elements
UI elements floating and oscillating as if weightless with different animation durations.
Perspective Scroll
Content at different Z depths creating a space flight effect with CSS perspective and translateZ.
Layered Paper
Stack of paper sheets with realistic shadows and slight rotation, spreading out on hover.
Isometric Grid
Interactive isometric grid where blocks rise and fall based on cursor proximity.
Depth of Field
Foreground/background with blur that changes focus on hover, simulating depth of field.
3D Room
Content placed on the floor and walls of a CSS perspective room that rotates on drag.
Floating Shadows
Elements with shadows moving independently as if a dynamic light source is moving.
View source code
<div class="demo-preview">
<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>.demo-preview,
.demo-preview *,
.demo-preview *::before,
.demo-preview *::after {
box-sizing: border-box
}
.demo-preview {
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;
}
.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;
}(function() {
// ==========================================
// 9. Floating Shadows - Dynamic light source
// ==========================================
document.querySelectorAll('[data-float-shadow]').forEach(function(container) {
var elements = container.querySelectorAll('.float-shadow-el');
container.addEventListener('mousemove', 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('mouseleave', 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.