CSS aspect-ratio Property
Description
The CSS aspect-ratio property is a modern tool that allows developers to define the proportional relationship between an element’s width and height. This ratio determines how an element scales when its size changes, ensuring that the element maintains a consistent shape regardless of the viewport or container dimensions. Unlike traditional approaches where developers often relied on padding tricks or JavaScript calculations to preserve dimensions, aspect-ratio provides a declarative, native CSS solution that is both simpler and more reliable. By specifying a ratio, such as 16/9 for a widescreen element or 1/1 for a square, the browser automatically adjusts the missing dimension when one dimension is explicitly defined.
One of the most powerful aspects of aspect-ratio is how it interacts with other sizing properties like width and height. When either width or height is defined, the browser uses the aspect ratio to calculate the unspecified dimension. For example, if you set the width of an element to 300px and the aspect ratio to 16/9, the height is automatically computed as 168.75px, maintaining the desired proportion. This automatic calculation is particularly useful for responsive design, where elements need to adapt fluidly to different screen sizes while preserving their intended appearance.
Additionally, aspect-ratio is beneficial for images, videos, and layout containers, helping prevent layout shifts and visual inconsistencies. When combined with properties like object-fit, it can ensure media retains its intended proportions within flexible containers. Moreover, it simplifies the creation of grid and flex layouts by letting elements naturally maintain their shape without extra wrappers or complex CSS rules. Overall, aspect-ratio is a versatile property that modernizes layout control, providing developers with a straightforward, CSS-only approach to maintain visual harmony across various devices and contexts.
Definition
- Initial value
- auto
- Applies to
- all elements except inline boxes and internal ruby or table boxes
- Inherited
- no
- Computed value
- as specified
- Animatable
- by computed value type
- JavaScript syntax
- object.style.aspectRatio
Interactive Demo
Syntax
aspect-ratio: auto | <ratio>
Values
- autoThe element does not have a preferred aspect ratio and the browser sets it automatically based on the width and height of the element.
- <ratio>The ratio is written as 16/9, here the first number is the width and the second number is the height. If any value is not specified, then it is considered equal to 1. Also, some ratios can be written in one number. For example, 2/1 can be written as 0.5, this will give the same result.
Example
Browser Support
The following information will show you the current browser support for the CSS aspect-ratio property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
