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 as 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 syntax
auto | <ratio>
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.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Intrinsic & Extrinsic Sizing Module Level 4 The definition of 'aspect-ratio' in that specification. |
Editor's Draft | Initial definition |
Initial value | auto |
---|---|
Applies to | all elements except inline boxes and internal ruby or table boxes |
Inherited | no |
Media | all |
Computed value | as specified |
Animation type | discrete |
Canonical order | per grammar |
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.
No compatibility data found. Please contribute data for "css.properties.aspect-ratio" (depth: 1) to the MDN compatibility data repository.