<ratio> CSS type

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

The <ratio> CSS data type describes the proportional relationship between two values. It mostly represents the aspect ratio, which relates width to height. For example, the <ratio> is used as a value for the aspect-ratio media feature in @media media queries, the aspect-ratio size feature in @container container queries, and as a value for the CSS aspect-ratio property.

Syntax

The <ratio> data type is a <number> followed by a forward slash ('/', Unicode U+002F SOLIDUS) and a second <number>. Both numbers must be positive. Spaces before and after the slash are optional. The first number represents the width, while the second represents the height. In addition a single <number> as a value is allowable.

Two ratios are compared using the quotients' numeric values. For example, 16/16 is less than 16/9 because it resolves to 1 while the second resolves to 1.7. This means a tall screen's aspect ratio is smaller than a wide screen's, and portrait images have smaller aspect ratios than landscape images.

Common aspect ratios

Ratio Usage
4/3 or 1.33333 A rectangle that is three units tall and four units wide Traditional TV format in the twentieth century.
16/9 or 1.7777778 A rectangle that is nine units tall and sixteen units wide Modern "widescreen" TV format.
185/100 or 1.85 A rectangle that is 1 unit tall and 1.85 units wide The most common movie format since the 1960s.
239/100 or 2.39 A rectangle that is 1 unit tall and 2.39 units wide "Widescreen," anamorphic movie format.

Formal syntax

<ratio> = 
<number [0,∞]> [ / <number [0,∞]> ]?

Examples

Use in a media query

css
@media screen and (aspect-ratio >= 16/9) {
  /* … */
}

Use in a @container size query

css
@container (aspect-ratio > 1) and (width < 20em) {
  /* … */
}

Use as a CSS property value

css
.square {
  aspect-ratio: 1 / 1;
}
.circle {
  aspect-ratio: 1;
  border-radius: 50%;
}
.portrait {
  aspect-ratio: 5 / 7;
}

Specifications

Specification
CSS Values and Units Module Level 4
# ratio-value

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
<ratio>
Chrome – Full support
Chrome 3 (Release date: 2009-09-15)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 3.5 (Release date: 2009-06-30)
footnote Full support
Opera – Full support
Opera 9.5 (Release date: 2008-06-12)
footnote Full support
Safari – Full support
Safari 5 (Release date: 2010-06-07)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 4.2 (Release date: 2010-11-22)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 4.2 (Release date: 2010-11-22)
footnote Full support
Accepts a single <number> as a value.
Experimental
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 78 (Release date: 2020-06-30)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also