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.

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 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

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

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 No support NoWebView 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 No support NoSamsung Internet Android No support No
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 No support NoWebView Android Full support 79Chrome Android Full support 79Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung 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.

See also