<div class="aspectratio">
  <div class="content">Aspect Ratio
    <br />
    16:9
  </div>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #222;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  gap: 10px;
}

.aspectratio {
  width: 50vmin;
  background-color: #09f;
  border: 1px solid #64f;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: change 5s linear alternate infinite;
  position: relative;
}

.aspectratio::after {
  content: "";
  height: 0;
  width: 1px;
  padding-bottom: 56.25%;
  margin: -1px;
  z-index: -1;
}

@keyframes change {
  0% {
    width: 50vmin;
  }
  100% {
    width: 80vmin;
  }
}

.content {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  line-height: 1.5;

  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.