Effets 3D & Perspective
Effets 3D, profondeur spatiale, parallax et motion path.
Mis à jour le
Comment ajouter de la profondeur 3D à une page web en CSS ?
Les effets 3D donnent de la profondeur à une interface en plaçant ses éléments dans un espace virtuel. En CSS, ils reposent sur la propriété perspective, sur transform-style: preserve-3d et sur les transformations 3D comme rotateY() ou translateZ() ; WebGL prend le relais quand une scène demande un vrai éclairage ou des centaines d'objets.
Comment choisir, performances et accessibilité
- Réservez la 3D CSS aux éléments avec lesquels on interagit : Card Flip 3D pour une carte tarif ou équipe, Perspective Tilt pour un visuel produit, 3D Carousel pour une galerie ; gardez WebGL pour les héros immersifs.
- N'animez que
transformetopacitypour que le navigateur utilise la carte graphique, évitez d'empiler beaucoup de calques 3D sur mobile et supprimez les grandes rotations pourprefers-reduced-motion. - Rotating Cube, Mouse Parallax Scene et Floating Shadows sont gratuits avec leur code complet ; les autres effets de la page sont inclus dans Premium.
De la vraie 3D, pas de la perspective CSS
Les effets de cette page simulent le relief en CSS. Le générateur SVG en 3D fabrique un volume réel : votre logo est extrudé, éclairé, il porte une ombre et se prend à la main.
L'aperçu et l'image sont gratuits. Le code s'emporte avec un abonnement.
Ouvrir le générateurRotating Cube
Cube 3D interactif qui suit le mouvement de la souris.
Voir le code source
<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
Retournement complet de carte avec effet 3D réaliste.
Perspective Tilt
Élément qui s'incline en 3D selon la position du curseur.
3D Carousel
Carrousel circulaire avec rotation 3D continue.
Folding Panel
Panneau qui se déplie comme du papier au survol.
3D Button Press
Bouton avec effet de pression 3D réaliste.
Layered Parallax 3D
Couches multiples avec effet de profondeur 3D.
Rotating Text
Texte avec rotation 3D animée en continu.
Isometric Grid
Grille isométrique avec cubes 3D interactifs.
Cube Auto-Rotation
Cube 3D avec rotation automatique continue.
Parallax Depth Layers
Couches empilées avec effet de profondeur 3D.
Fold Effect Card
Carte qui se plie vers l'intérieur au survol.
Door Open Effect
Porte 3D qui s'ouvre pour révéler le contenu.
Page Turn Effect
Effet de pages qui se tournent au survol.
Prism Rotation
Prisme hexagonal avec rotation automatique.
Floating Elements 3D
Éléments flottants avec rotation 3D animée.
3D Button Press V2
Bouton 3D avec effet de pression perspective.
Carousel 3D V2
Carrousel circulaire avec 5 éléments en rotation.
Shadow Perspective
Carte avec ombre 3D réaliste qui réagit au survol.
Mouse Parallax Scene
Scène multi-couches (étoiles, lune, montagnes, arbres) réagissant au curseur à des vitesses différentes.
Voir le code source
<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
Carte avec éléments superposes (fond, texte, icône) se séparant en 3D au survol avec translate3d.
Floating Elements
Éléments UI flottant et oscillant comme en apesanteur avec des durées d'animation différentes.
Perspective Scroll
Contenu a différentes profondeurs Z créant un effet de vol spatial avec CSS perspective et translateZ.
Layered Paper
Pile de feuilles de papier avec ombres réalistes et légère rotation, qui se déploient au survol.
Isometric Grid
Grille isométrique interactive ou les blocs se lèvent et s'abaissent selon la proximité du curseur.
Depth of Field
Avant/arrière-plan avec flou qui change de focus au survol, simulant la profondeur de champ.
3D Room
Contenu place sur le sol et les murs d'une pièce CSS perspective qui tourne au glissement.
Floating Shadows
Éléments avec ombres se déplaçant indépendamment comme si une source lumineuse dynamique bougeait.
Voir le code source
<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
Galerie d'images ou chaque élément s'incline indépendamment selon la distance du curseur.