Open In App

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

Last Updated : 02 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • aspect-ratio Property:
    • Defines the aspect ratio of an element, specifying the relationship between width and height.
    • The value is expressed as a ratio, e.g., width / height.
    • Can be applied to any element, including images, videos, and containers.
  • Responsive Design: The aspect-ratio property is valuable in creating responsive layouts where maintaining specific proportions is crucial.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads