aspect-ratio

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.

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 by box-sizing.

Formal definition

Initial valueauto
Applies toall elements except inline boxes and internal ruby or table boxes
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

auto | <ratio>

Examples

Examples of values for aspect-ratio

aspect-ratio: 1 / 1; 
aspect-ratio: 16 / 9;

Mapping width and height to aspect-ratio

Browsers have added an internal aspect-ratio property that applies to replaced elements and other related elements that accept width and height attributes. This appears in the browser's internal UA stylesheet. 

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);
}

You can read more about this feature in Setting Height And Width On Images Is Important Again.

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
aspect-ratio
Experimental
Chrome Partial support 79
Notes
Partial support 79
Notes
Notes Chrome 79 adds internal support only for mapped values
Edge Partial support 79
Notes
Partial support 79
Notes
Notes Edge 79 adds internal support only for mapped values
Firefox Partial support 71
Notes
Partial support 71
Notes
Notes Firefox 71 adds internal support only for mapped values
No support 69 — 71
Notes Disabled
Notes Firefox 69 adds internal support only for mapped values
Disabled From version 69 until version 71 (exclusive): this feature is behind the layout.css.width-and-height-map-to-aspect-ratio.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari Partial support 14
Notes
Partial support 14
Notes
Notes Safari 14 adds internal support only for mapped values
WebView Android Partial support 79
Notes
Partial support 79
Notes
Notes Webview 79 adds internal support only for mapped values
Chrome Android Partial support 79
Notes
Partial support 79
Notes
Notes Chrome 79 adds internal support only for mapped values
Firefox Android No support NoOpera Android No support NoSafari iOS Partial support 14
Notes
Partial support 14
Notes
Notes Safari 14 adds internal support only for mapped values
Samsung Internet Android Partial support 12.0
Notes
Partial support 12.0
Notes
Notes Samsung Internet 12.0 adds internal support only for mapped values
Internal mapping of width and height
Experimental
Chrome Full support 79Edge Full support 79Firefox Full support 71
Full support 71
No support 69 — 71
Disabled
Disabled From version 69 until version 71 (exclusive): this feature is behind the layout.css.width-and-height-map-to-aspect-ratio.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari Full support 14WebView Android Full support 79Chrome Android Full support 79Firefox Android No support NoOpera Android No support NoSafari iOS Full support 14Samsung Internet Android Full support 12.0

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.

See also