HTML DOM Style transformStyle Property


The HTML DOM style transformStyle property returns and apply a 2D or 3D transformation to an element in an HTML document.

Syntax

Following is the syntax −

  • Returning transformStyle

object.style.transformStyle
  • Modifying transformStyle

object.style.transformStyle = “value”

Values

Here, value can be −

ValueExplanation
inheritIt inherits this property value from its parent element.
initialIt set this property value to its default value.
flatIt sets the child element to not to preserve its 3D position.
preserve-3dIt sets the child element to preserve its 3D position.

Example

Let us see an example of HTML DOM style transformStyle property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      background: lightgreen;
      height: 100vh;
      text-align: center;
   }
   .outer-box {
      position: relative;
      height: 200px;
      width: 200px;
      margin: 80px;
      padding: 5px;
      border: 2px solid black;
   }
   .inner-box1 {
      padding: 50px;
      position: absolute;
      background-color: coral;
      transform: rotateY(40deg);
   }
   .inner-box2 {
      padding: 40px;
      position: absolute;
      background-color: lightblue;
      transform: rotateY(60deg);
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
</head>
<body>
<h1>DOM Style transformStyle Property Example</h1>
<div class="outer-box">Outer Box
<div class="inner-box1">Inner Box1
<div class="inner-box2">Inner Box2</div>
</div>
</div>
<button onclick="add()" class="btn">Set transformStyle</button>
<script>
   function add() {
      document.querySelector(".inner-box1").style.transformStyle = "preserve-3d";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Set transformStyle” button to apply transform style on Inner Box 1 −

Updated on: 01-Jul-2020

25 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements