HTML DOM Style perspectiveOrigin Property


The HTML DOM Style perspectiveOrigin property returns and modify where a 3D element is placed on x-axis and y-axis in an HTML document.

Syntax

Following is the syntax −

1. Returning perspectiveOrigin

object.perspectiveOrigin

2. Modifying perspectiveOrigin

object.perspectiveOrigin = “value”

Here, value can be −

ValueExplanation
initialIt set this property value to its default value.
inheritIt inherits this property value from its parent element.
x-axis y-axisHere x-axis represent where the view is placed on the x-axis. y-axis represent where the view is placed on the y-axis.

Let us see an example of HTML DOM Style perspectiveOrigin Property −

Example

Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
      perspective: 100px;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
   .box {
      text-align: center;
      width: 200px;
      height: 200px;
      background-color: #db133a;
      transform: rotateX(25deg);
      margin: 2rem auto;
   }
</style>
<body>
<h1 style="text-align:center">DOM Style perspectiveOrigin Property Demo</h1>
<div class='box'></div>
<button class="btn" onclick="set()">Set PerspectiveOrigin</button>
<script>
   function set() {
      document.body.style.perspectiveOrigin = "20% 50%";
   }
</script>
</body>
</html>

Output

Click on “Set PerspectiveOrigin” button to set perspective origin of red box.

Updated on: 17-Feb-2021

11 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements