CSS Data Type
Description
The <ratio> CSS data type represents a proportional relationship between two numbers, typically used to define an aspect ratio for elements. Unlike fixed units such as <length> or percentages, a <ratio> expresses a relative width-to-height relationship, allowing elements to scale dynamically while maintaining a specific proportion. This is particularly useful for responsive designs, where preserving the shape of an element, such as an image, video, or container, is important regardless of the screen size.
In practice, <ratio> is often employed in properties like aspect-ratio, which can accept values in the form of “width / height.” For example, setting an aspect ratio of 16:9 ensures that an element retains that rectangular shape even when resized:
.video-container {
aspect-ratio: 16 / 9;
width: 100%;
background-color: #000;
}
One of the advantages of the <ratio> type is that it allows for flexible, content-aware layouts without relying on fixed heights or complex JavaScript calculations. It can also interact seamlessly with other CSS features, such as min-width or max-height, enabling developers to constrain the scaling behavior while keeping the intended proportion intact.
Additionally, the <ratio> data type is not limited to integer values. Decimal ratios are valid, which allows for fine-tuning layouts:
.square-box {
aspect-ratio: 1 / 1; /* Perfect square */
width: 150px;
background-color: coral;
}
.banner {
aspect-ratio: 2.35 / 1; /* Cinematic banner ratio */
width: 100%;
background-color: #333;
}
By using <ratio>, designers can ensure consistent visual experiences across different devices, making it a powerful addition to the modern CSS toolbox.
Syntax
property: <ratio>;
Values
- <ratio>Is a positive (not zero or negative) <integer> followed by optional whitespace, followed by a solidus ('/'), followed by optional whitespace, followed by a positive <integer>.
Example
Browser Support
The following information will show you the current browser support for the CSS ratio data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
This data type is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 3rd January 2026
