Use a CSS custom property, --aspect-ratio, to define the desired aspect ratio. Set the container element to position: relative and height: 0. Calculate its height using the calc() function and the custom property.