Back to Concepts
CSS UniverseTrack 8: Transitions & Animation3D Transforms & Perspective
Transitions & Animation · Track 8Core Concept 32
3D Transforms, Perspective & Card Flips
Break through the screen surface. Learn the 3D coordinate system (X, Y, Z), understand how perspective controls camera focal length, and build the classic 3D flipping card with preserve-3d and backface-visibility.
1. Mental Model: Camera Distance & The Z-Axis
In 2D CSS, you only have X (horizontal) and Y (vertical). 3D introduces the Z-axis, pointing directly perpendicular from your monitor screen into your eyes.
Small perspective (200px)
Camera is 2 inches away. Extreme fisheye lens drama! Edge vanishing points slant sharply.
Sweet Spot (800px - 1000px)
Matches the natural perspective of a human standing 2 feet away from a desktop computer monitor.
No perspective (Default)
Orthographic projection. Rotating an element in 3D just squishes it flat like a deflating balloon!
2. The Sacred 3D Card Flip Trinity
/* 1. Parent: Establishes the 3D Theater room */
.card-container {
perspective: 1000px;
}
/* 2. Flipper: Preserves true 3D spatial depth for children */
.card-flipper {
transform-style: preserve-3d;
transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
/* 3. Faces: Front & Back hide their reverse sides */
.card-front, .card-back {
backface-visibility: hidden;
position: absolute; inset: 0;
}
.card-back {
transform: rotateY(180deg);
}
3. Interactive Studio: Live 3D Credit Card Gimbal
Camera Perspective800px
Rotate X (Pitch / Tilt)0°
Rotate Y (Yaw / Spin)0°
Computed 3D Transform
perspective: 800px;
transform: rotateX(0deg) rotateY(0deg);
transform: rotateX(0deg) rotateY(0deg);
First-Year Student Traps: 3D Transforms
- 1.Declaring perspective on the wrong element: Always put
perspective: 1000pxon the parent container (the scene wrapper), NOT on the rotating card itself! Declaring perspective on the element itself creates bizarre localized camera distortions. - 2.The Missing WebKit Prefix for backface-visibility: Safari on macOS and iOS frequently glitches or fails to hide the back face of 3D cards without
-webkit-backface-visibility: hidden;. Always declare both prefixes together!
Next Masterclass
Continue to Concept 33Motion Path: offset-path & SVG Trajectories
Animate icons and rockets along custom curved SVG paths using offset-path and offset-distance.