Course contentsShow
← Web Development
Lesson 1263 of 2,98222. Responsive Images and MediaFree lesson

The Old Padding-Bottom Technique

Understand the legacy padding-bottom percentage trick for maintaining aspect ratios before aspect-ratio existed.

The Old Padding-Bottom Technique

You'll learn how developers maintained aspect ratios before the modern aspect-ratio property existed.

The Core Challenge

Before CSS gained the aspect-ratio property (which you just learned about), developers faced a tricky problem: how do you force an element to maintain a specific aspect ratio, especially when its width changes responsively?

The Padding-Bottom Hack

The solution was a clever trick based on an unusual CSS behavior: percentage-based padding is calculated relative to the element's width, even for padding-top and padding-bottom.

Here's the pattern:

.aspect-ratio-container {
  position: relative;
  width: 100%; /* or any responsive width */
  padding-bottom: 56.25%; /* 16:9 ratio (9/16 = 0.5625) */
  height: 0; /* Collapse the height */
}

.aspect-ratio-container img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

How It Works

The magic happens because padding-bottom: 56.25% means "make the bottom padding 56.25% of the parent's width." Since the container has height: 0, all vertical space comes from padding. The image inside is positioned absolutely to fill that padded space.

To calculate the percentage for any aspect ratio: divide height by width and multiply by 100. For example, 9÷16×100 = 56.25% for 16:9 ratio.

Why It's "Old"

This technique was everywhere for years, but it's now considered legacy. The modern aspect-ratio property does the same thing with far simpler, more readable code. However, you'll still encounter this pattern in older codebases and documentation.

Key Takeaway: The padding-bottom percentage technique exploited CSS's width-based percentage calculation to maintain aspect ratios before aspect-ratio existed, but it's now superseded by cleaner modern approaches.