×

Save Your Code

If you click the save button, your code will be saved, and you get an URL you can share with others.

By clicking the "Save" button you agree to our terms and conditions.

Report Error

×

Save to Google Drive

If you have a Google account, you can save this code to your Google Drive.

Google will ask you to confirm Google Drive access.

×

Open from Google Drive

If you have saved a file to Google Drive, you can open it here:

Result Size: 625 x 571
x
 
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1 {
  height: 200px;
  width: 200px;
  margin: auto;
  border: 1px solid black;
}
#DIV2 {
  width: 150px;
  height: 150px;
  border: 1px solid black;
  background-color: coral;
  -ms-transform: rotate(45deg); /* IE 9 */
  -webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
  transform: rotate(45deg);
}
#DIV2original {
  position: absolute;
  width: 150px;
  height: 150px;
  border: 1px dashed grey;
  background-color: lightgrey;
  opacity: 0.5;
}
</style>
</head>
<body>
<h1>Change transform-origin with JavaScript</h1>
<p>Click the "Try it" button to set the origin of the rotation to 0 for both the x-axis and the y-axis:</p>
<p><b>Note: </b>The grey DIV element indicates where the DIV2 element would be without the transformation.</p>
<button onclick="myFunction()">Try it</button>
<div id="DIV1">DIV1
   <div id="DIV2original">DIV2</div> <div id="DIV2">DIV2</div>
</div>
<script>
function myFunction() {
×

Report a Problem: