3D transforms and perspective
Definition and purpose
3D transforms add a depth coordinate to the rendered plane. Perspective makes objects closer to the viewer appear larger; rotateY turns a plane around its vertical axis. A flat element still has no physical thickness.
Shared projection
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #p { perspective: 400px; width: 200px; } #a { width: 100px; height: 40px; transform: translateZ(200px); } </style> </head> <body> <div id="p"> <div id="a">Card</div> </div> </body></html>At half the perspective distance toward the viewer, the projected width doubles.
Syntax and mental model
The perspective property on a parent projects transformed children using a shared viewpoint; perspective() inside a transform list projects the element itself in that composition. transform-style: preserve-3d allows descendants to share a 3D space when grouping properties do not force flattening. backface-visibility: hidden hides the rear-facing side.
Hide a rear face
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { transform: perspective(400px) rotateY(180deg); backface-visibility: hidden; } </style> </head> <body> <div id="p"> <div id="a">Card</div> </div> </body></html>The transform function supplies projection without setting the perspective property. The rear side is hidden.
Common mistakes
Do not put perspective on the child expecting it to project that child as a parent would. Backface hiding does not create an accessible alternate face.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: 2D transforms and origin. Next lesson: Transitions and timing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
3D transforms and perspective — knowledge check
Five questions on 3d transforms and perspective.
Where is a shared perspective property normally set?
What does perspective() belong to?
What does rotateY rotate around?
Which value hides a rear-facing plane?
What can force 3D flattening?