Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<head>
<style>
#DIV1 {
  height: 200px;
  width: 200px;
  margin: auto;
  border: 1px solid black;
  position: relative;
}
#DIV2 {
  width: 150px;
  border: 1px solid black;
  background-color: coral;
  aspect-ratio: 1;
}
#DIV2original {
  position: absolute;
  z-index: -1;
  opacity: 0.5;
  width: 150px;
  border: 1px dashed grey;
  background-color: lightgrey;
  aspect-ratio: 1;
}
</style>
</head>
<body>
<h1>Change aspect-ratio property with JavaScript</h1>
<p>Click the "Try it" button to set new aspect-ratio property "16/9":</p>
<p><b>Note: </b>The grey DIV element indicates original aspect-ratio of DIV2 element.</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() {