{"id":332875,"date":"2021-01-20T10:54:28","date_gmt":"2021-01-20T18:54:28","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=332875"},"modified":"2022-09-07T13:54:15","modified_gmt":"2022-09-07T20:54:15","slug":"aspect-ratio","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/a\/aspect-ratio\/","title":{"rendered":"aspect-ratio"},"content":{"rendered":"\n

The CSS property aspect-ratio<\/code> lets you create boxes that maintain proportional dimensions where the height<\/code> and width<\/code> of a box are calculated automatically as a ratio. It’s a little math-y, but the idea is that you can divide one value by another on this property and the calculated value ensures a box stays in that proportion.<\/p>\n\n\n\n

In other words, this property helps us to size elements consistently, so the ratio of an element stays the same as it grows or shrinks.<\/p>\n\n\n\n\n\n\n\n

.element {\n  aspect-ratio: 2 \/ 1; \/* ↔️ is double the ↕️ *\/\n}\n\n.element {\n  aspect-ratio: 1 \/ 1; \/* ⏹ a perfect square *\/\n}<\/code><\/pre>\n\n\n\n

aspect-ratio<\/code> is defined in the CSS Box Sizing Module Level 4 specification<\/a>, which is currently in Working Draft. That means it’s still in progress and has a chance of changing. But with Chrome and Firefox supporting it behind an experimental flag, and Safari Technology Preview adding support for it in early 2021<\/a>, there are strong signals that aspect-ratio<\/code> is gaining a lot of momentum.<\/p>\n\n\n

Syntax<\/h3>\n\n\n
aspect-ratio: auto || <ratio>;<\/code><\/pre>\n\n\n\n

In plain English: aspect-ratio<\/code> is either assumed to be auto<\/code> by default, or accepts a <ratio><\/code> as a value where <width \/ height><\/code>.<\/p>\n\n\n\n