property

aspect-ratio — CSS reference

Sets a preferred width-to-height ratio. Initial auto; not inherited. A specified ratio guides an automatically sized axis, but explicit dimensions or min/max constraints may override it. For auto plus a ratio on a replaced element, the intrinsic ratio is used when available. A specified ratio generally uses the box selected by box-sizing.

Formal Syntax & Structure

css syntaxcss
auto || <ratio>

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS box geometry lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#a{width:160px;aspect-ratio:2 / 1} #b{width:160px;height:30px;aspect-ratio:2 / 1} #c{width:160px;aspect-ratio:2 / 1;min-height:100px}</style><body><div id="a" class="sample"></div><div id="b" class="sample"></div><div id="c" class="sample"></div></body></html>
CSS Reference