<div class="aspectratio">--aspect-ratio: 16 / 9</div>

<div class="aspectratio" style="--aspect-ratio: 1.3333">--aspect-ratio: 4 / 3</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;
  padding: 10px;
}

@property --aspect-ratio {
  syntax: "<number>";
  initial-value: 1.7777;
  inherits: false;
}

.aspectratio {
  aspect-ratio: var(--aspect-ratio);
  width: 300px;
  background-color: #f09;

  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  resize: horizontal;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.