CKTIS / CSS
aspect-ratio — preferred width-to-height ratio for automatic sizing
`aspect-ratio` supplies a preferred width/height ratio used when at least one box dimension is automatic.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
auto || <ratio>aspect-ratio supplies a preferred width/height ratio used when at least one box dimension is automatic.
A 16 / 9 box with fixed width and auto height resolves to 160x90. When both dimensions are explicit, the same ratio leaves 160x70; the negative ratio -1 / 1 is supported as false.
Grammar: auto || <ratio>.
A ratio transfers a definite size through the ratio-dependent axis before min/max constraints. A bare <ratio> uses dimensions of the box selected by box-sizing. By contrast, auto and auto <ratio> always use content-box dimensions for the natural/preferred-ratio rule: on a replaced element, auto 1 / 1 chooses its natural ratio when available, otherwise the supplied ratio. Content-based automatic minimums can enlarge a flex/grid item, so min-width: 0 may be needed when overflow is intended. A preferred ratio does not turn a normal box into a replaced element and has no preferred-size effect when both width and height are non-auto. CSS Sizing Level 4 is an exploratory Editor’s Draft; test interactions with intrinsic sizing and replaced content.
Examples
document.body.innerHTML =
'<style>.box{display:block;width:160px;box-sizing:border-box}.derived{height:auto;aspect-ratio:16 / 9}.fixed{height:70px;aspect-ratio:16 / 9}</style>' +
'<div class="box derived"></div><div class="box fixed"></div>';
await new Promise(requestAnimationFrame);
const size=selector=>{const box=document.querySelector(selector).getBoundingClientRect();return Math.round(box.width)+'x'+Math.round(box.height);};
console.log('auto-height='+size('.derived')+'; fixed-both='+size('.fixed')+'; computed='+getComputedStyle(document.querySelector('.derived')).aspectRatio+'; negative='+CSS.supports('aspect-ratio','-1 / 1'));Result
auto-height=160x90; fixed-both=160x70; computed=16 / 9; negative=false
`aspect-ratio` supplies a preferred width/height ratio used when at least one box dimension is automatic.