The aspect-ratio
CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.
This property is not yet implemented in browsers, however some browsers are implementing this internally in order to provide the aspect ratio mapping described below.
Syntax
aspect-ratio: 1 / 1; /* Global values */ aspect-ratio: inherit; aspect-ratio: initial; aspect-ratio: unset;
Values
<auto>
- Replaced elements with an intrinsic aspect ratio use that aspect ratio, otherwise the box has no preferred aspect ratio. Size calculations involving intrinsic aspect ratio always work with the content box dimensions.
<ratio>
- The box’s preferred aspect ratio is the specified ratio of
width
/height
. Size calculations involving preferred aspect ratio work with the dimensions of the box specified bybox-sizing
.
Formal definition
Initial value | auto |
---|---|
Applies to | all elements except inline boxes and internal ruby or table boxes |
Inherited | no |
Computed value | as specified |
Animation type | discrete |
Formal syntax
auto | <ratio>
Examples
Mapping width and height to aspect-ratio
Firefox has added an internal aspect-ratio
property (in version 69 onwards) that applies to replaced elements and other related elements that accept width
and height
attributes. This appears in the browser's internal UA stylesheet. Chrome is also shipping this feature.
In Firefox, the internal stylesheet rule looks like this:
img, input[type="image"], video, embed, iframe, marquee, object, table { aspect-ratio: attr(width) / attr(height); }
Specifications
Specification | Status | Comment |
---|---|---|
CSS Box Sizing Module Level 4 The definition of 'aspect-ratio' in that specification. |
Editor's Draft | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
aspect-ratio | Chrome
Partial support
79
| Edge
Partial support
79
| Firefox
Partial support
71
| IE No support No | Opera No support No | Safari No support No | WebView Android
Partial support
79
| Chrome Android
Partial support
79
| Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
Internal mapping of width and height | Chrome Full support 79 | Edge Full support 79 | Firefox
Full support
71
| IE No support No | Opera No support No | Safari No support No | WebView Android Full support 79 | Chrome Android Full support 79 | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
Legend
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.