aspect-ratio
The aspect-ratio CSS property allows you to define the desired width-to-height ratio of an element's box. This means that even if the parent container or viewport size changes, the browser will adjust the element's dimensions to maintain the specified width-to-height ratio. The specified aspect ratio is used in the calculation of auto sizes and some other layout functions.
At least one of the box's sizes needs to be automatic in order for aspect-ratio to have any effect. If neither the width nor height is an automatic size, then the provided aspect ratio has no effect on the box's preferred sizes.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 88 | 88 | 89 | 15 | 88 | 15 | |
auto | 88 | 88 | 89 | 15 | 88 | 15 |
| HTML attribute | ||||||
aspect_ratio_computed_from_attributes Aspect ratio computed from `width` and `height` attributes | 79 | 79 | 71 | 15 | 79 | 15 |
aspect_ratio_computed_from_attributes Aspect ratio computed from `width` and `height` attributes | 79 | 79 | 71 | 14 | 79 | 14 |
- This browser only partially implements this feature
- This feature was removed in a later browser version (15)
- Safari doesn't preserve space for images without a valid `src`, which may disrupt layouts that rely on lazy loading (see bug 224197).
- This browser only partially implements this feature
- This feature was removed in a later browser version (15)
- Safari on iOS doesn't preserve space for images without a valid `src`, which may disrupt layouts that rely on lazy loading (see bug 224197).
Syntax
.video-wrapper {
aspect-ratio: 16 / 9;
width: 100%;
}
.avatar {
aspect-ratio: 1;
width: 48px;
border-radius: 50%;
object-fit: cover;
} Live demo
Use cases
-
Media placeholders
Reserve space for images or video thumbnails to reduce layout shift while content loads.
-
Consistent cards
Keep visual tiles uniform even when their content or viewport width changes.
Cautions
- The ratio sets the box shape, not the content fitting behavior, so images may still need object-fit.
- Fixed ratios can hide or crop content if the box contains more text than expected.
Accessibility
- Stable proportions reduce layout jump, which helps users maintain orientation while a page is loading.