There are a few ways to do this. This example is JavaScript free but will require a parent element. Observe the following...
<div id="container">
<div id="element"></div>
</div>
#container {
display: inline-block;
position: relative;
width: 100px;
}
#container:after {
content: '';
display: block;
margin-top: 100%;
}
#element {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: dodgerblue;
}
Whenever width is changed, so is height, equally. Supplied below is a demo, while using jQuery, is just for an easy way to manipulate the element width.
// -- 100 x 100
$('#container').click(function() {
$(this).width(50); // -- 50 x 50
});
JSFiddle Link - demo
JSFiddle Link - additional demo - %
based - (re-size output window to see scaling)
Additionally, for a short and much simpler answer, use vw
units. Observe the following...
<div></div>
div {
width:20vw;
height:20vw;
background-color: dodgerblue;
}
JSFiddle Link - vw
demo
Here is a decent writeup on vw
and other similar units that may be of interest