CSS Reference ยท Transforms, Transitions and Animations
The transform-style property
Reference for the CSS transform-style property: keep child elements in a shared 3D space with preserve-3d, and learn which properties flatten it again.
The transform-style property decides whether the children of a transformed element live in the same 3D space as their parent or are flattened onto the parent's plane. With flat, the default, children are drawn as a picture on the parent's surface, so their own 3D transforms look flat. With preserve-3d, they stay separate 3D objects that can sit in front of and behind each other.
You need it whenever you build a cube, a flipping card or any scene where several 3D-transformed elements are nested.
.scene { transform-style: preserve-3d; }
Try it
In the flat version the two layers are squashed onto one plane, so their depth difference has no effect. With preserve-3d the layers keep their gap in depth and the rotation reveals it.
Syntax
transform-style: flat | preserve-3d;
- Initial value:
flat - Applies to: transformable elements
- Inherited: no
- Animatable: no (discrete)
- Computed value: as specified, but forced to
flatby some other properties (see below)
Values
| Value | Description |
|---|---|
flat |
Children are flattened into the plane of the element. |
preserve-3d |
Children are positioned in the element's 3D space and can intersect or overlap in depth. |
Usage notes
- Set it on the parent, not the child. Every element between the scene and the 3D-transformed layers needs
preserve-3d, or the chain breaks. - These properties force
flaton the element (as used value):overflowother thanvisible,opacityless than 1,filter,clip-path,mask,isolation: isolateandmix-blend-modeother thannormal. If a 3D scene collapses, look for one of these. perspectiveis separate. Putperspectiveon the container above the scene to get depth;transform-styleonly keeps the nesting.- Backfaces. Use
backface-visibility: hiddenon card faces so you see only the side facing you. - Cost. Large 3D scenes with many layers can be heavy on low-end devices.
Browser support
Supported in every current browser.