Tillitsdone
down Scroll to discover

CSS transform-style 3D Positioning Control

The css transform-style property controls how child elements are rendered in 3D space.

Use 'flat' to flatten elements or 'preserve-3d' for dynamic 3D effects.
thumbnail

Introduction

The transform-style property in CSS is a handy tool for web developers and designers. It lets you control how child elements are positioned in 3D space. By using this property, you can create visually appealing and interactive 3D transformations, enhancing the user experience on your websites.

This feature is widely supported across devices and browser versions, making it reliable for web development projects. Let’s dive into the transform-style property, covering its specifications, descriptions, syntax, values, formal definitions, examples, browser compatibility, and related resources. By the end, you’ll know how to implement and use the transform-style property effectively in your web projects.

Specification

The transform-style property is defined in the CSS Transforms Module Level 2. This module outlines how CSS transformations work, including how elements and their children are rendered in 3D space. The transform-style property specifies whether the children of an element are positioned in 3D space or flattened.

You can find the official specification in the [CSS Transforms Module Level 2]WebsiteUrl. This document provides detailed information on the property, including its syntax, values, and expected behavior.

Description

The transform-style property in CSS controls how child elements are rendered in 3D space. It specifies whether the children of an element are positioned in 3D space or flattened in the plane of the element. This property is useful for creating complex 3D transformations and enhancing the visual appeal of web designs.

When transform-style is set to preserve-3d, the child elements maintain their 3D positioning, allowing for more dynamic and interactive effects. Conversely, setting the property to flat causes the child elements to be flattened in the plane of the parent element, which can be useful for simplifying the visual presentation.

It’s important to note that the transform-style property is not inherited. This means it must be explicitly set for all non-leaf descendants of the element. Additionally, certain CSS properties can force the element to have a used value of transform-style: flat, even when preserve-3d is specified. These properties include:

  • overflow: any value other than visible or clip.
  • opacity: any value less than 1.
  • filter: any value other than none.
  • clip: any value other than auto.
  • clip-path: any value other than none.
  • isolation: used value of isolate.
  • mask-image: any value other than none.
  • mask-border-source: any value other than none.
  • mix-blend-mode: any value other than normal.
  • contain: paint and any other property/value combination that causes paint containment. This includes any property that affects the used value of the contain property, such as content-visibility: hidden.

Syntax

/* Keyword values */
transform-style: flat;
transform-style: preserve-3d;
/* Global values */
transform-style: inherit;
transform-style: initial;
transform-style: revert;
transform-style: revert-layer;
transform-style: unset;

Explanation:

  • flat: This value indicates that the children of the element are lying in the plane of the element itself, meaning they do not preserve their 3D position. This is the default value.
  • preserve-3d: This value specifies that the children of the element should be positioned in 3D space, allowing for more dynamic and interactive 3D effects.
  • inherit: This value inherits the transform-style property from its parent element.
  • initial: This value sets the property to its default value.
  • revert: This value reverts the property to the default value as defined by the user agent (browser).
  • revert-layer: This value reverts the property to the value specified in the next outer CSS layer.
  • unset: This value resets the property to its natural value, which means it behaves as though the property is not set at all.

Values

flat

The flat value places the child elements in the same plane as the parent element. This means that the child elements do not preserve their 3D position and are flattened. This value is useful for creating a simplified visual presentation.

preserve-3d

The preserve-3d value enables the child elements to preserve their 3D position. This allows for more dynamic and interactive 3D effects, making it a powerful tool for creating complex and visually appealing web designs.

initial

The initial value sets the property to its default value. This is useful when you want to reset the property to its initial state.

inherit

The inherit value inherits the transform-style property from its parent element. This can be useful for maintaining consistency across nested elements.

revert

The revert value reverts the property to the default value as defined by the user agent (browser). This is useful for overriding previously set values and returning to the browser’s default behavior.

revert-layer

The revert-layer value reverts the property to the value specified in the next outer CSS layer. This is useful for managing styles in a layered CSS architecture.

unset

The unset value resets the property to its natural value, which means it behaves as though the property is not set at all. This is useful for removing any previously set values and allowing the default behavior to take effect.

Formal Definition

Initial Value

  • Initial Value: flat
    • The default behavior of the transform-style property is to flatten the child elements in the plane of the parent element.

Applies To

  • Applies To: Transformable elements
    • The transform-style property can be applied to any element that supports CSS transformations.

Inherited

  • Inherited: No
    • The transform-style property is not inherited by default. This means it must be explicitly set for all non-leaf descendants of the element.

Computed Value

  • Computed Value: As specified
    • The computed value of the transform-style property is the same as the value specified in the CSS.

Animation Type

  • Animation Type: Discrete
    • The transform-style property does not support smooth transitions between values. It changes abruptly to the specified value.

Creates Stacking Context

  • Creates Stacking Context: Yes
    • The transform-style property creates a new stacking context, which affects how elements are layered and rendered on the screen.

Formal Syntax

transform-style =
flat |
preserve-3d
  • flat: Indicates that the children of the element are lying in the plane of the element itself.
  • preserve-3d: Indicates that the children of the element should be positioned in 3D space.

Examples

Example: Using transform-style: preserve-3d

HTML

<!DOCTYPE html>
<html>
<head>
<style>
.parent {
margin: 20px;
border: 1px dotted;
height: 200px;
width: 200px;
background-color: green;
transform: rotateX(15deg);
transform-style: preserve-3d;
}
.child {
margin: 20px;
border: 1px dotted;
height: 250px;
width: 250px;
background-color: lightgreen;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<p>The CSS transform-style Property is used to set if the children of elements are positioned in 3D space or flattened.</p>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>

Output

In this example, the child element will preserve its 3D positioning, creating a more dynamic and interactive visual effect.

Placeholder because (https://media.Website.org/wp-content/uploads/20190725223028/preserve3d.png not found)

Example: Using transform-style: initial

HTML

<!DOCTYPE html>
<html>
<head>
<style>
.parent {
margin: 20px;
border: 1px dotted;
height: 200px;
width: 200px;
background-color: green;
transform: rotateX(15deg);
transform-style: initial;
}
.child {
margin: 20px;
border: 1px dotted;
height: 250px;
width: 250px;
background-color: lightgreen;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<p>The CSS transform-style property determines if children elements are positioned in 3D space or flattened.</p>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>

Output

In this example, the transform-style property is reset to its default value, making the child element flattened in the plane of the parent element.

Placeholder because (https://media.Website.org/wp-content/uploads/20190725223027/initial6.png not found)

Example: Using transform-style: inherit

HTML

<!DOCTYPE html>
<html>
<head>
<style>
.main {
transform-style: flat;
}
.parent {
margin: 20px;
border: 1px dotted;
height: 200px;
width: 200px;
background-color: green;
transform: rotateX(15deg);
transform-style: inherit;
}
.child {
margin: 20px;
border: 1px dotted;
height: 250px;
width: 250px;
background-color: lightgreen;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<p>The CSS transform-style property determines if children elements are positioned in 3D space or flattened.</p>
<div class="main">
<div class="parent">
<div class="child"></div>
</div>
</div>
</body>
</html>

Output

In this example, the child element inherits the transform-style property from its parent element, making the child element flattened in the plane of the parent element.

Placeholder because (https://media.Website.org/wp-content/uploads/20190725223024/inherit2.png not found)

Example: Using transform-style: flat

HTML

<!DOCTYPE html>
<html>
<head>
<style>
.parent {
margin: 20px;
border: 1px dotted;
height: 200px;
width: 200px;
background-color: green;
transform: rotateX(15deg);
transform-style: flat;
}
.child {
margin: 20px;
border: 1px dotted;
height: 250px;
width: 250px;
background-color: lightgreen;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<h1>CSS transform-style Property</h1>
<p>The CSS transform-style property determines if children elements are positioned in 3D space or flattened.</p>
<div class="parent">
<div class="child"></div>
</div>
</body>
</html>

Output

In this example, the child element is flattened in the plane of the parent element, resulting in a simplified visual presentation.

Placeholder because (https://media.Website.org/wp-content/uploads/20190725223018/flat.png not found)

Transform Style Demonstration

HTML

<section id="example-element">
<div class="face front">1</div>
<div class="face back">2</div>
<div class="face right">3</div>
<div class="face left">4</div>
<div class="face top">5</div>
<div class="face bottom">6</div>
</section>
<div class="checkbox">
<label for="preserve"><code>preserve-3d</code></label>
<input type="checkbox" id="preserve" checked />
</div>

CSS

#example-element {
margin: 50px;
width: 100px;
height: 100px;
transform-style: preserve-3d;
transform: rotate3d(1, 1, 1, 30deg);
}
.face {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
position: absolute;
backface-visibility: inherit;
font-size: 60px;
color: #fff;
}
.front {
background: rgb(90 90 90 / 70%);
transform: translateZ(50px);
}
.back {
background: rgb(0 210 0 / 70%);
transform: rotateY(180deg) translateZ(50px);
}
.right {
background: rgb(210 0 0 / 70%);
transform: rotateY(90deg) translateZ(50px);
}
.left {
background: rgb(0 0 210 / 70%);
transform: rotateY(-90deg) translateZ(50px);
}
.top {
background: rgb(210 210 0 / 70%);
transform: rotateX(90deg) translateZ(50px);
}
.bottom {
background: rgb(210 0 210 / 70%);
transform: rotateX(-90deg) translateZ(50px);
}

JavaScript

const cube = document.getElementById("example-element");
const checkbox = document.getElementById("preserve");
checkbox.addEventListener("change", () => {
cube.style.transformStyle = checkbox.checked ? "preserve-3d" : "flat";
});

Explanation

  1. HTML Structure:
    • The section element with the id example-element represents the cube.
    • Inside the cube, there are six div elements, each representing a face of the cube (front, back, right, left, top, bottom).
    • A checkbox is provided to toggle between preserve-3d and flat styles.
  2. CSS Styling:
    • The #example-element is styled to have a margin, width, height, and an initial transformation to rotate the cube.
    • The transform-style: preserve-3d property is set to ensure the cube faces are positioned in 3D space.
    • Each face of the cube is styled with a different background color and transformation to position it correctly in the 3D space.
  3. JavaScript Interaction:
    • A JavaScript event listener is added to the checkbox. When the checkbox is toggled, the transform-style property of the cube is updated to either preserve-3d or flat.

Result

In this demonstration, you will see a 3D cube that rotates in 3D space. The checkbox allows you to toggle between the preserve-3d and flat styles. When preserve-3d is selected, the cube faces are positioned in 3D space, creating a dynamic and interactive visual effect. When flat is selected, the cube faces are flattened onto the plane of their parent, and you might not be able to see them at all, depending on the browser you are using.

Browser Compatibility

The transform-style property is widely supported across many modern browsers, making it a reliable choice for web development projects. Here is an overview of the browser compatibility for the transform-style property:

Supported Browsers

  • Chrome: Supported since version 36.0.
  • Internet Explorer: Supported since version 11.0.
  • Firefox: Supported since version 16.0.
  • Safari: Supported since version 9.0.
  • Opera: Supported since version 23.0.

Compatibility Table

BrowserVersionSupported Since
Chrome36.0July 2014
Internet Explorer11.0October 2013
Firefox16.0October 2012
Safari9.0September 2015
Opera23.0July 2013

Additional Notes

  • In earlier versions of Chrome and Safari, the transform-style property required the -webkit- prefix.
  • In earlier versions of Firefox, the transform-style property required the -moz- prefix.
  • In earlier versions of Opera, the transform-style property required the -webkit- prefix.

Checking Compatibility

To ensure that your web projects are compatible with a wide range of browsers, it’s essential to test your CSS transformations across different browsers and versions. Using tools like BrowserStack or CrossBrowserTesting can help you identify and fix compatibility issues.

Conclusion

The transform-style property is a powerful tool for web developers and designers, enabling them to create dynamic and interactive 3D transformations. With widespread browser support, you can confidently use this property in your web projects to enhance the user experience and create visually appealing designs.

By understanding the browser compatibility of the transform-style property, you can ensure that your web projects function correctly across different browsers and devices, providing a seamless experience for all users.

See Also

To further enhance your understanding and application of CSS transformations, you may find the following resources helpful:

Related CSS Properties

  • [CSS Transforms]WebsiteUrl: Learn more about how to use CSS transforms to manipulate elements in 2D and 3D space.
  • [CSS transform-origin]WebsiteUrl: Discover how to set the origin point for CSS transformations, allowing for more precise control over transformations.
  • [CSS transition]WebsiteUrl: Explore how to create smooth transitions between different states of an element, enhancing the visual appeal of your web designs.

Tutorials and Guides

  • [Using CSS Transforms]WebsiteUrl: A comprehensive guide on using CSS transforms to create dynamic and interactive web designs.
  • [CSS 2D Transforms Tutorial]WebsiteUrl: Learn the basics of 2D transformations and how to apply them to your web projects.
  • [CSS 3D Transforms Tutorial]WebsiteUrl: Dive into the world of 3D transformations and discover how to create stunning 3D effects with CSS.

Reference Guides

  • [HTML Reference Guide]WebsiteUrl: A comprehensive reference for HTML elements and attributes, helping you build robust and semantic web pages.
  • [CSS Reference Guide]WebsiteUrl: A detailed guide to CSS properties and values, assisting you in creating visually appealing and functional web designs.

Additional Resources

  • [MDN Web Docs]WebsiteUrl: The Mozilla Developer Network (MDN) offers a wealth of resources for web developers, including documentation, tutorials, and examples on a wide range of web technologies.
  • [W3Schools CSS Transforms]WebsiteUrl: Learn the basics of CSS transforms with interactive examples and tutorials.
  • [CSS-Tricks]WebsiteUrl: A popular web development blog featuring articles, tutorials, and tips on CSS and other web technologies.

These resources will help you deepen your knowledge of CSS transformations and equip you with the tools and techniques needed to create engaging and visually appealing web designs. By exploring these references and tutorials, you can enhance your web development skills and create more dynamic and interactive web experiences.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.