Skip to content

Aspect Ratio

Easy — everyone uses thisFrontend

ELI5 — The Vibe Check

The aspect-ratio property tells an element to keep its proportions, like a photo that stays rectangular no matter how you resize it. No more padding-bottom hacks to make responsive video containers. We suffered for years, and now it's one line of CSS.

Real Talk

The CSS aspect-ratio property sets a preferred width-to-height ratio for an element, replacing the legacy padding-top percentage hack. It works with replaced and non-replaced elements and respects explicit width/height constraints. Widely supported in all modern browsers.

Show Me The Code

.video-container {
  aspect-ratio: 16 / 9;
  width: 100%;
}
.avatar {
  aspect-ratio: 1;
}

When You'll Hear This

"Use aspect-ratio: 16/9 instead of that padding-bottom: 56.25% monstrosity" / "The image grid uses aspect-ratio: 1 for perfect squares"

Made with passive-aggressive love by manoga.digital. Powered by Claude.