CSS transform-style Property
The CSS transform-style property determines whether an element's children are rendered in a shared three-dimensional space or flattened into the element's plane.
It is used to create layered 3D effects, rotating cubes, card interfaces, and nested transformations. The preserve-3d value allows descendants to retain their 3D positions, while flat renders them as a flattened representation. The property does not create perspective or apply a transformation by itself.
transform-style Syntax
The transform-style property accepts one of two keywords: flat or preserve-3d.
Basic Syntax
.example {
transform-style: preserve-3d;
}
Available Values
.example {
transform-style: flat;
}
.example {
transform-style: preserve-3d;
}
CSS-Wide Keywords
.example {
transform-style: initial;
}
.example {
transform-style: inherit;
}
.example {
transform-style: unset;
}
.example {
transform-style: revert;
}
.example {
transform-style: revert-layer;
}
Invalid Examples
.example {
transform-style: 3d;
}
.example {
transform-style: preserve;
}
.example {
transform-style: flat preserve-3d;
}
.example {
transform-style: 50%;
}
The property does not accept lengths, percentages, multiple values, or alternative keywords such as 3d.
Property Values
| Value | Description |
|---|---|
flat |
Flattens the element's descendants into the plane of the element before applying the element's transformation. |
preserve-3d |
Allows descendants to retain their positions in a shared 3D rendering context. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | flat |
| Inherited | No |
| Applies to | Transformable elements |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not accepted |
| Specification | CSS Transforms Module Level 2 |
Note: Although the computed value may be preserve-3d, certain CSS properties can force the used value to flat. These conditions are explained in the Forced Flattening section.
How It Works
The transform-style property controls how the browser combines an element's transformed descendants into the final rendered result.
Step 1: Create a Parent and Child
<div class="scene">
<div class="parent">
<div class="child">3D Child</div>
</div>
</div>
Step 2: Establish Perspective
.scene {
perspective: 600px;
}
Perspective creates the visual depth effect for transformed descendants.
Step 3: Enable 3D Rendering
.parent {
transform-style: preserve-3d;
transform: rotateY(30deg);
}
Step 4: Position the Child in 3D Space
.child {
transform: translateZ(60px);
}
The child is positioned along the Z axis. Because the parent preserves 3D rendering, the child's depth is retained in the shared 3D scene.
Step 5: Change the Parent to flat
.parent {
transform-style: flat;
transform: rotateY(30deg);
}
The child's transformed appearance is flattened into the parent's plane before the parent's transformation is applied.
Understanding the Difference
With preserve-3d, descendants can participate in the same 3D rendering context. With flat, their rendered result is flattened at the parent boundary.
The flat Value
The flat value is the default. It causes the element's descendants to be flattened into its plane before the element's transformation is applied.
Basic Example
.parent {
transform-style: flat;
}
Flattened 3D Children
.parent {
transform-style: flat;
transform: rotateY(30deg);
}
.child {
transform: translateZ(50px);
}
The child's depth does not remain independent when the parent's flattened representation is transformed.
Default Behavior
If transform-style is omitted, the element uses flat.
When to Use flat
Use flat when an element's descendants do not need to participate in a shared 3D rendering context with elements outside that boundary.
Important Distinction
The flat value does not disable the transform property or prevent an element from being rotated in 3D. It controls how the element's descendants are combined.
The preserve-3d Value
The preserve-3d value allows transformed descendants to retain their positions in three-dimensional space.
Basic Example
.parent {
transform-style: preserve-3d;
}
Preserving Child Depth
.parent {
transform-style: preserve-3d;
transform: rotateY(30deg);
}
.child {
transform: translateZ(50px);
}
Multiple Depth Layers
.parent {
transform-style: preserve-3d;
}
.front {
transform: translateZ(60px);
}
.middle {
transform: translateZ(20px);
}
.back {
transform: translateZ(-40px);
}
The descendants occupy different depths within the shared 3D rendering context.
Nested 3D Containers
.outer {
transform-style: preserve-3d;
}
.inner {
transform-style: preserve-3d;
}
.deep-child {
transform: translateZ(80px);
}
Each intermediate container must preserve 3D rendering when its descendants need to remain in the same 3D context.
When to Use preserve-3d
Use this value for 3D cubes, layered cards, rotating objects, and interfaces where multiple descendants need independent depth positions.
Important Consideration
The preserve-3d value does not create perspective. A separate perspective effect is generally needed to make depth visually apparent.
Working With perspective
The perspective property and transform-style serve different purposes in 3D layouts.
Establishing Perspective
.scene {
perspective: 800px;
}
Perspective determines how depth affects the apparent size and position of transformed descendants.
Preserving 3D Space
.object {
transform-style: preserve-3d;
}
The object allows its descendants to remain positioned in 3D space.
Complete Example
.scene {
perspective: 800px;
}
.object {
transform-style: preserve-3d;
transform: rotateY(30deg);
}
.object .front {
transform: translateZ(50px);
}
.object .back {
transform: translateZ(-50px);
}
Perspective Distance
Smaller positive perspective distances generally produce a stronger perspective effect, while larger distances produce a subtler effect.
Using perspective() in transform
.object {
transform-style: preserve-3d;
transform: perspective(800px) rotateY(30deg);
}
The perspective() transform function applies perspective within an element's transformation list. It is not identical to applying the perspective property to a parent.
Important Distinction
Perspective controls the visual projection of depth. The transform-style property controls whether descendants preserve their depth relationships.
Nested 3D Elements
Nested 3D layouts require careful control of each container's rendering behavior.
HTML Structure
<div class="scene">
<div class="outer">
<div class="inner">
<div class="layer">3D Layer</div>
</div>
</div>
</div>
Preserving Depth Through Multiple Levels
.scene {
perspective: 800px;
}
.outer {
transform-style: preserve-3d;
transform: rotateY(20deg);
}
.inner {
transform-style: preserve-3d;
transform: rotateX(20deg);
}
.layer {
transform: translateZ(80px);
}
Flattening an Intermediate Container
.inner {
transform-style: flat;
}
Changing the intermediate container to flat prevents its descendants from continuing in the same 3D rendering context beyond that boundary.
Why Repeated Declarations Matter
The transform-style property is not inherited. A parent using preserve-3d does not automatically give the same value to its children.
Recommended Approach
Apply preserve-3d to each intermediate container that must preserve its descendants' depth relationships.
Forced Flattening
Certain CSS properties require an element's descendants to be rendered as a flattened representation. These properties can force the used value of transform-style to flat, even when preserve-3d is specified.
Opacity Below 1
.object {
transform-style: preserve-3d;
opacity: 0.8;
}
An opacity value below 1 requires flattening for the affected element.
Overflow Clipping
.object {
transform-style: preserve-3d;
overflow: hidden;
}
Overflow values other than visible or clip can force flattening.
Overflow clip Exception
.object {
transform-style: preserve-3d;
overflow: clip;
}
The clip value does not itself force flattening under the CSS Transforms specification.
CSS Filters
.object {
transform-style: preserve-3d;
filter: blur(4px);
}
A filter value other than none requires flattening.
Clipping and Masking
.object {
transform-style: preserve-3d;
clip-path: circle(45%);
}
Clipping and masking effects can require the descendants to be flattened.
Isolation
.object {
transform-style: preserve-3d;
isolation: isolate;
}
Creating an isolated stacking context can force flattening.
Other Grouping Properties
Other properties that can force flattening include non-normal blending modes, certain mask settings, and contain: paint or other containment values that establish paint containment.
Avoiding Unintended Flattening
Apply visual effects such as opacity and filters to a suitable outer wrapper when possible, keeping the inner 3D container free of grouping properties that would flatten its descendants.
Important Distinction
The specified or computed value may remain preserve-3d, while the used value becomes flat because of another property.
Working With backface-visibility
The backface-visibility property controls whether the back side of a transformed element is visible when facing the viewer.
Basic Example
.face {
backface-visibility: hidden;
}
Two-Sided Card Structure
<div class="scene">
<div class="card">
<div class="front">Front</div>
<div class="back">Back</div>
</div>
</div>
Card CSS
.scene {
perspective: 800px;
}
.card {
position: relative;
transform-style: preserve-3d;
transition: transform 0.6s ease;
}
.front,
.back {
position: absolute;
inset: 0;
backface-visibility: hidden;
}
.back {
transform: rotateY(180deg);
}
.card.is-flipped {
transform: rotateY(180deg);
}
How the Properties Work Together
The transform-style: preserve-3d declaration allows both faces to retain their 3D orientation. The backface-visibility: hidden declaration prevents the reverse side of each face from being displayed.
Important Consideration
Hiding a face visually does not automatically remove its interactive content from keyboard navigation or the accessibility tree. Interactive card designs need additional state management.
Related CSS Properties
The transform-style property works with other CSS properties used to create 2D and 3D transformations.
transform
.example {
transform: rotateY(30deg);
}
Applies transformations to an element.
transform-origin
.example {
transform-origin: center;
}
Specifies the point around which transformations occur.
transform-box
.example {
transform-box: border-box;
}
Selects the reference box used for transformation calculations.
perspective
.scene {
perspective: 800px;
}
Controls the perspective projection of transformed descendants.
perspective-origin
.scene {
perspective-origin: center;
}
Specifies the viewpoint origin for perspective.
backface-visibility
.face {
backface-visibility: hidden;
}
Controls visibility of an element's reverse side.
rotate
.example {
rotate: y 30deg;
}
Applies an individual rotation transformation.
translate
.example {
translate: 0 0 50px;
}
Moves an element along the X, Y, or Z axis.
Complete Example
.scene {
perspective: 800px;
}
.object {
transform-style: preserve-3d;
transform-origin: center;
transform: rotateY(30deg);
}
.object .face {
backface-visibility: hidden;
transform: translateZ(50px);
}
Inheritance
The transform-style property is not inherited. Each element uses its own value unless inheritance is explicitly requested.
Parent Element Example
.parent {
transform-style: preserve-3d;
}
Child Element
.child {
transform-style: flat;
}
The child uses its own value, which is flat by default.
Explicit Inheritance
.child {
transform-style: inherit;
}
The child receives the parent's computed value.
Restore the Initial Value
.child {
transform-style: initial;
}
This restores flat.
Using unset
.child {
transform-style: unset;
}
Because the property is not inherited, unset restores the initial value.
Nested 3D Containers
Set preserve-3d on each intermediate container that needs to preserve its descendants' 3D relationships.
Practical Examples
3D Card Container
.card {
transform-style: preserve-3d;
transform: rotateY(20deg);
}
Layered 3D Interface
.layers {
transform-style: preserve-3d;
}
.layer-front {
transform: translateZ(60px);
}
.layer-back {
transform: translateZ(-60px);
}
Rotating 3D Object
.object {
transform-style: preserve-3d;
animation: object-spin 5s linear infinite;
}
@keyframes object-spin {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
Nested 3D Groups
.outer-group,
.inner-group {
transform-style: preserve-3d;
}
.inner-group {
transform: rotateX(25deg);
}
Flat Card Rendering
.flat-card {
transform-style: flat;
transform: rotateY(30deg);
}
3D Icon Layers
.icon-container {
transform-style: preserve-3d;
}
.icon-front {
transform: translateZ(20px);
}
.icon-back {
transform: translateZ(-20px);
}
3D Scene With Perspective
.scene {
perspective: 900px;
}
.scene-object {
transform-style: preserve-3d;
transform: rotateX(20deg) rotateY(30deg);
}
Reduced Motion Alternative
@media (prefers-reduced-motion: reduce) {
.object {
animation: none;
}
}
transform-style Example
This example compares flat and preserve-3d. Both panels contain a child translated along the Z axis, but only the second parent preserves the child's depth when the parent rotates.
HTML Example
<div class="style-demo">
<div class="style-sample">
<strong>transform-style: flat;</strong>
<div class="style-scene">
<div class="style-parent style-flat">
<div class="style-child">3D Child</div>
</div>
</div>
</div>
<div class="style-sample">
<strong>transform-style: preserve-3d;</strong>
<div class="style-scene">
<div class="style-parent style-preserve">
<div class="style-child">3D Child</div>
</div>
</div>
</div>
</div>
CSS Example
.style-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
gap: 20px;
}
.style-sample strong {
display: block;
margin-bottom: 12px;
}
.style-scene {
display: flex;
align-items: center;
justify-content: center;
min-height: 190px;
padding: 30px;
border: 1px dashed #94a3b8;
background: #f8fafc;
perspective: 600px;
}
.style-parent {
display: flex;
align-items: center;
justify-content: center;
width: 120px;
height: 100px;
border: 2px solid #2563eb;
background: rgba(147, 197, 253, 0.2);
transform: rotateY(45deg);
}
.style-child {
display: flex;
align-items: center;
justify-content: center;
width: 85px;
height: 55px;
background: #93c5fd;
border: 2px solid #1d4ed8;
color: #1e3a8a;
font-size: 12px;
font-weight: bold;
transform: translateZ(65px);
}
.style-flat {
transform-style: flat;
}
.style-preserve {
transform-style: preserve-3d;
}
Understanding the Results
Both parent elements use rotateY(45deg), and both child elements use translateZ(65px).
flat Result
The first parent flattens its descendants before applying its own rotation. The child's depth is not preserved independently through the parent's transformation.
preserve-3d Result
The second parent preserves the child's 3D position, allowing its Z-axis translation to affect the final perspective projection.
Experiment With the Parent Rotation
.style-parent {
transform: rotateY(65deg);
}
Increasing the rotation makes the depth relationship more noticeable.
Experiment With the Child Depth
.style-child {
transform: translateZ(100px);
}
Increasing the Z-axis translation changes the child's apparent position and size when 3D depth is preserved.
Experiment With Perspective
.style-scene {
perspective: 350px;
}
A shorter perspective distance produces a stronger depth effect.
Accessibility Considerations
The transform-style property does not directly change semantic meaning or keyboard behavior, but 3D transformations can affect the visibility and usability of content.
Respect Reduced Motion Preferences
Continuous 3D rotation and perspective animations may cause discomfort for motion-sensitive users.
@media (prefers-reduced-motion: reduce) {
.rotating-object {
animation: none;
transition: none;
}
}
Keep Text Readable
Strong perspective and rotation effects can make text difficult to read. Avoid placing essential instructions on heavily transformed surfaces.
Manage Hidden Card Faces
When creating two-sided cards, ensure that controls on the hidden face cannot receive keyboard focus until that face is available.
Preserve Logical Focus Order
3D transformations change visual presentation but do not automatically change the document's keyboard navigation order.
Provide Non-Animated Alternatives
Important content should remain available when motion effects are disabled.
Avoid Unexpected Overlap
Elements translated along the Z axis may visually overlap nearby content. Test interactive controls at different viewport sizes.
Test Browser Zoom
Verify that 3D interfaces remain readable and usable when users increase browser zoom or text size.
Common Mistakes
Using an Invalid Value
.example {
transform-style: 3d;
}
Use preserve-3d instead.
Expecting preserve-3d to Create Perspective
The preserve-3d value preserves depth relationships but does not create perspective by itself.
Forgetting Intermediate Containers
Nested 3D layouts may require preserve-3d on multiple intermediate elements.
Using opacity Below 1
.object {
transform-style: preserve-3d;
opacity: 0.5;
}
Opacity below 1 forces the used value of transform-style to flat.
Using overflow: hidden
.object {
transform-style: preserve-3d;
overflow: hidden;
}
This can flatten descendants and prevent the intended shared 3D rendering context.
Applying Filters to a 3D Container
Filters other than none can force flattening.
Confusing transform-style With transform
The transform property applies transformations. The transform-style property controls how descendants participate in 3D rendering.
Confusing transform-style With backface-visibility
The backface-visibility property controls whether an element's reverse side is visible. It does not preserve a shared 3D context.
Assuming the Property Is Inherited
The property is not inherited. Each intermediate 3D container may need its own declaration.
Expecting 3D Depth Without a 3D Transformation
Setting preserve-3d alone does not visibly move descendants along the Z axis.
Ignoring Hidden Interactive Content
Visually hidden card faces may still contain keyboard-focusable controls.
Ignoring Reduced Motion Preferences
Continuous 3D animations should provide a reduced-motion alternative.
Important Considerations
Keep the following points in mind when using transform-style:
- The property controls whether descendants preserve their 3D positions or are flattened.
- The initial value is
flat. - The property is not inherited.
- The property applies to transformable elements.
- The property accepts
flatandpreserve-3d. - The
flatvalue flattens descendants into the element's plane. - The
preserve-3dvalue allows descendants to share a 3D rendering context. - The property does not create perspective.
- The property does not apply a transformation by itself.
- Use
perspectivewhen a visual depth projection is needed. - Use
translateZ()to position descendants along the Z axis. - Nested 3D containers may each require
preserve-3d. - Some grouping properties force the used value to
flat. - Opacity below 1 can force flattening.
- Overflow values other than
visibleandclipcan force flattening. - Filters, clipping, masking, and paint containment can force flattening.
- The computed value may remain
preserve-3deven when the used value isflat. - The property does not control the visibility of an element's reverse side.
- Use
backface-visibilityto control reverse-side visibility. - The property uses discrete animation between its values.
- 3D transforms do not change normal document flow.
- Test nested 3D rendering across supported browsers.
- Respect reduced motion preferences for animated 3D effects.
Browser Support
The CSS transform-style property is widely supported in modern browsers. Support for preserve-3d and nested 3D rendering is well established, although complex scenes involving grouping properties, clipping, or nested transformations may require additional testing.
For current compatibility information, visit Can I Use? and search for transform-style.
Basic Declaration
.example {
transform-style: preserve-3d;
}
3D Scene Example
.scene {
perspective: 800px;
}
.object {
transform-style: preserve-3d;
transform: rotateY(30deg);
}
Feature Detection
@supports (transform-style: preserve-3d) {
.object {
transform-style: preserve-3d;
}
}
Fallback Behavior
If a browser does not recognize preserve-3d, the declaration is ignored and the element generally uses the default flat behavior.
Testing Recommendations
Test nested 3D elements, perspective, backface visibility, and forced-flattening conditions in the browsers your website supports. Feature detection confirms that the value is recognized but does not guarantee identical rendering of complex scenes.
Specifications
The transform-style property is defined in the CSS Transforms Module Level 2 specification.
CSS Transforms Module Level 2 - The transform-style Property
The specification defines flat and preserved 3D rendering, shared 3D rendering contexts, and conditions that require flattening.
For additional documentation and examples, consult MDN Web Docs.
