CSS Ratio Value

The CSS aspect ratio is defined as the ratio of width to height (width:height). and aspect ratio of features specified as <ratio> value which represent the width to height viweport. We can also use min-aspect-ratio and max-aspect-ratio for min and max values respectively.

Valid ratios include:

16/9, 4/3, 800/600, and 1/1

For more https://www.geeksforgeeks.org/css-media-rule/

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
  
    <style>
        @media (min-aspect-ratio: 9/5) {
            div {
                background: #808000;
            }
        }
  
        @media (max-aspect-ratio: 3/2) {
            div {
                background: #ff99aa;
            }
        }
  
        @media(aspect-ratio:1/1) {
            div {
                background: #424395;
            }
        }
    </style>
</head>
  
<body>
    <div id="hello">
        LOOK AT THE ASPECT RATIOS.
        GEEKS FOR GEEKS BEST WEBSITE GEEKS.
    </div>
</body>
  
</html>

chevron_right


Output:

After Resize:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.