Keep up aspect ratio of a div with CSS

Ask a question

<p>I want to create a <code>div</code> that can change its width/height as the window’s width changes.</p><p>Are there any CSS3 rules that would allow the height to change according to the width, <strong>while maintaining its aspect ratio</strong>?</p><p>I know I can do this via JavaScript, but I would prefer using only CSS.</p>

Coin iconoffer bounty
add comment

1 Answer


You can give height in “vh” and width in “vw”. It will make your dive responsive as your screen size get smaller or wider. div will adjust itself according to window’s height & width.


Check this example:

add comment

Your Answer