Maintain the aspect ratio of a div with CSS
Asked 07 September, 2021
Viewed 611 times
  • 61
Votes

I want to create a div that can change its width/height as the window's width changes.

Are there any CSS3 rules that would allow the height to change according to the width, while maintaining its aspect ratio?

I know I can do this via JavaScript, but I would prefer using only CSS.

div keeping aspect ratio according to width of window

30 Answer