CSS propertyTransforms
transform-style
Decides whether an element’s children live in a shared 3D space or are flattened.
- Initial value
flat- Inherited
- No
- Animatable
- no
- Applies to
- transformable elements
- JavaScript
element.style.transformStyle = "preserve-3d"
Example
#CSS
.cube {
transform-style: preserve-3d;
animation: spin 6s linear infinite;
}
@keyframes spin {
to { transform: rotateX(360deg) rotateY(360deg); }
}Example HTML
<style>
.cube-scene { perspective: 600px; width: 90px; height: 90px; margin: 24px auto; }
.cube { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; animation: spin 6s linear infinite; }
.cube div { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; opacity: .9; }
.f1 { background: #7c3aed; transform: translateZ(45px); }
.f2 { background: #0ea5e9; transform: rotateY(180deg) translateZ(45px); }
.f3 { background: #10b981; transform: rotateY(90deg) translateZ(45px); }
.f4 { background: #f59e0b; transform: rotateY(-90deg) translateZ(45px); }
.f5 { background: #f43f5e; transform: rotateX(90deg) translateZ(45px); }
.f6 { background: #6366f1; transform: rotateX(-90deg) translateZ(45px); }
@keyframes spin { to { transform: rotateX(360deg) rotateY(360deg); } }
</style>
<div class="cube-scene"><div class="cube"><div class="f1">1</div><div class="f2">2</div><div class="f3">3</div><div class="f4">4</div><div class="f5">5</div><div class="f6">6</div></div></div>Preview
Definition and usage
#The transform-style property is set on the parent of elements transformed in 3D. By default (flat), children are flattened onto the parent’s plane, so nested 3D rotations do not form a real solid.
The preserve-3d value keeps the third dimension: children can be in front of and behind each other, and rotating the parent rotates the whole scene. This lets you build a cube from six faces or a flip card.
Some properties, such as overflow: hidden or filter, force flattening and disable the preserve-3d effect.
Syntax
#Syntax
transform-style: flat | preserve-3d;Values
#- The inner tile is flattened onto the parent’s plane.
- The inner tile floats above the parent in 3D space.
Values in practice
#flat
The inner tile is flattened onto the parent’s plane.
.demo { transform-style: flat; }preserve-3d
The inner tile floats above the parent in 3D space.
.demo { transform-style: preserve-3d; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- If a 3D solid “flattens”, look for
overflow: hidden,filter, oropacitybelow 1 on the parent. - Respect the reduced-motion setting: under
prefers-reduced-motion: reduce, stop rotating scenes.
Related entries
#- backface-visibilityDecides whether the back of an element rotated in 3D is visible.
- perspectiveAdds depth to the 3D transforms of an element’s children.
- transformMoves, rotates, scales, or skews an element without affecting the page layout.
- animationA shorthand that sets all the parameters of an animation based on @keyframes.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.