CSS aspect-ratio Property Explained

What the CSS aspect-ratio property does, with an example.

Published November 5, 2026

aspect-ratio sets a preferred width-to-height ratio for a box, such as 16 / 9, so elements keep their shape as they resize without padding hacks.

How it works

Give one dimension and the browser computes the other from the ratio. It also reserves space for images to prevent layout shift.

Content that is too large can still stretch the box.

Values and effects

aspect-ratio: 16 / 9; → widescreen video
aspect-ratio: 1 / 1; → square
aspect-ratio: 4 / 3; → classic photo
aspect-ratio: auto 3 / 2; → use image's own ratio if available

Practical examples

Video embed

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

Square avatar

.avatar { width: 64px; aspect-ratio: 1; border-radius: 50%; }

Prevent layout shift

img { aspect-ratio: 3 / 2; width: 100%; height: auto; }

Common mistakes

  • Setting both width and height and so ignoring the ratio.
  • Overflowing content stretching the box.
  • Using old padding-top hacks unnecessarily.

Key takeaways

  • aspect-ratio in one line: aspect-ratio sets a preferred width-to-height ratio for a box, such as 16 / 9, so elements keep their shape as they resize without padding hacks.
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

Is it supported?

Yes in all modern browsers.

Is aspect-ratio supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles