Reduce any width × height to its lowest-terms aspect ratio, scale to a target dimension, and emit ready-to-use CSS.
→ 800 × 450
/* CSS aspect-ratio (Chrome 88+, Firefox 89+, Safari 15+) */
.container {
aspect-ratio: 16 / 9;
width: 100%;
}
/* Padding-bottom hack (universal support) */
.container {
position: relative;
padding-bottom: 56.2500%; /* 16:9 */
}
.container > * {
position: absolute; inset: 0;
}