Open In App

What is the use of the aspect-ratio property in CSS?

The aspect-ratio Property in CSS is used to explicitly set the aspect ratio of an element, ensuring that it maintains a specific width-to-height proportion. This property is particularly useful in responsive design to control the size and proportions of elements.

Note: The aspect-ratio property is applied to an element and accepts a ratio value, such as width / height.

Syntax:

/* Setting the aspect ratio of a box to 16:9 */
.aspect-box {
aspect-ratio: 16 / 9;
}

Features:

Article Tags :