How to maintain the aspect ratio of a div with CSS?

.ratio-4-3 {
  padding-bottom: 75%;
  width: 100%;
  background-color: #ff0000;
}
<div class="ratio-4-3"></div>
Copy

September 8th, 2019

# Padding bottom trick

Add to bookmarks

The padding bottom trick is helpful if you want to maintain the size of a <div> containing a video or image with a specific aspect ratio. The math behind it is simple: height / width = padding-bottom value

aspect ratio padding-bottom value
4:3 75%
16:9 56.25%
3:2 66.6%
8:5 62.5
Tracking with Matomo to improve the UX. See Privacy Policy for more details.