Transform-Style and Backface-Visibility
You'll learn how to control 3D space in nested elements and hide the back side of flipped elements.
When you rotate elements in 3D space, two questions arise: Do child elements stay flat with their parent, or do they exist in true 3D space? And what happens when an element faces away from you?
Transform-Style: Preserving 3D Space
The transform-style property controls how nested transformed elements render in 3D:
flat(default): Children are flattened into the parent's planepreserve-3d: Children maintain their own 3D position in space
Think of it like a pop-up book. With flat, all the pages lie flat on one surface. With preserve-3d, pages can stand up and create depth.
.card-container {
transform-style: preserve-3d;
transform: rotateY(45deg);
}
.card-front, .card-back {
/* These now exist in true 3D space relative to container */
}
Without preserve-3d, child elements rotate with their parent but don't maintain separate 3D positioning.
Backface-Visibility: Controlling Reversed Faces
When you rotate an element 180° or more, you're looking at its back. backface-visibility controls whether that back side is visible:
visible(default): You see through to the back (reversed content)hidden: The back is invisible
This is crucial for card-flip effects. Imagine a playing card: when it flips, you shouldn't see the front side reversed through the back.
.card-front {
backface-visibility: hidden;
}
.card-back {
backface-visibility: hidden;
transform: rotateY(180deg); /* Start facing away */
}
When the container rotates, one face hides while the other appears—creating a clean flip effect.
Key Takeaway: Use transform-style: preserve-3d to maintain true 3D positioning in nested elements, and backface-visibility: hidden to prevent showing the reversed back of rotated elements—essential for realistic 3D effects like card flips.