aspect-ratio
Widely availableSince 202197% of users
Sets a preferred ratio for an element's width and height, ensuring it maintains a specific shape (like square or widescreen) even as it resizes.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyModernIn every major browser since September 2021. Widely available since March 2024.
The old way and the modern waySee the snippet: Aspect ratios without the padding hack →
Old way 11 lines
.video-wrapper {
position: relative;
padding-top: 56.25%;
}
.video-wrapper > * {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}Modern 3 lines
.video-wrapper {
aspect-ratio: 16 / 9;
}See how modern your own CSS is.Check your CSS →
Quick facts
- Initial value
auto- Inherited
- No
- Applies to
- all elements except inline boxes and internal ruby or table boxes
- Animation type
- byComputedValueType
Quick example
.video-container {
aspect-ratio: 16 / 9;
width: 100%;
/* height is calculated automatically */
}Values
autoRelated snippet
Aspect ratios without the padding hackLayout →aspect-ratio browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2021.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
88+
89+
15+
88+Mobile
88+Android
89+Android
15+iOS