CSSApr 2, 2026 ยท Updated Oct 13, 2026 ยท 3 min read

How to Set CSS Aspect Ratio on Any Element

The CSS aspect-ratio property maintains an element's proportions regardless of its width. Set aspect-ratio: 16 / 9 and the element is always 16:9 โ€” whether it's 300px wide or 1200px wide. It replaces the decades-old padding-bottom percentage hack with a single, readable property.

๐Ÿ“
Try the CSS Aspect Ratio
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01The aspect-ratio Property02Replacing the Padding-Bottom Hack03Preventing Layout Shift with Images04Worked Example: What Chromium Does05Common Aspect Ratios

The aspect-ratio Property

The syntax is straightforward:

.video-container {
  aspect-ratio: 16 / 9;
  width: 100%;
}
.square-card {
  aspect-ratio: 1 / 1;
  width: 300px;
}

The element calculates its height from the width and ratio. If both width and height are set, the ratio is ignored. And by default the ratio is a minimum, not a fixed size: if the content is taller than the ratio allows, the box grows to fit it (see the measurements below). Add min-height: 0 with overflow: auto if the shape must hold.

Replacing the Padding-Bottom Hack

Before aspect-ratio, developers used padding-bottom percentages to maintain ratios:

/* Old way */
.video-wrapper { position: relative; padding-bottom: 56.25%; height: 0; }
.video-wrapper iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
/* New way */
.video-wrapper { aspect-ratio: 16 / 9; }
.video-wrapper iframe { width: 100%; height: 100%; }

The new way is cleaner, more readable, and doesn't require absolute positioning tricks.

Preventing Layout Shift with Images

You do not need CSS for this. Put width and height attributes on the <img> and keep height: auto in your CSS: since 2021 every major browser's built-in stylesheet turns those attributes into aspect-ratio: auto 1600 / 900, so the correct space is reserved before the image downloads. The aspect-ratio: attr(width) / attr(height) rule that circulates online is unnecessary โ€” the browser already does exactly that. Use an explicit ratio with object-fit: cover only when you want every image cropped to the same shape.

Worked Example: What Chromium Does

We tested in Chromium 141 with a 400px-wide container and an image URL that never finishes loading (script and results in our test folder, October 13, 2026):

CaseHeight
<img width="1600" height="900">, CSS width:100%; height:auto, before load225 px โ€” space reserved (computed aspect-ratio: auto 1600 / 900)
Same image without the attributes0 px โ€” the page will jump when it loads
aspect-ratio: 16/9, short content225 px
Same box, content longer than fits324 px โ€” grew to fit the text
Same, plus min-height: 0; overflow: auto225 px โ€” ratio held, content scrolls
aspect-ratio: 16/9 with height: 100px100 px โ€” explicit height wins

Common Aspect Ratios

16:9 โ€” video, YouTube embeds, widescreen displays. 4:3 โ€” traditional TV, iPad. 1:1 โ€” Instagram posts, avatars, product thumbnails. 9:16 โ€” vertical video (Stories, Reels). 21:9 โ€” ultrawide/cinematic. 3:2 โ€” DSLR photos. 4:5 โ€” Instagram portrait. Use the calculator to find the ratio for any pixel dimensions.

Frequently Asked Questions

What does CSS aspect-ratio do?+
It maintains an element's width-to-height proportion. Set aspect-ratio: 16 / 9 and the element always stays at 16:9 regardless of its width. The height is calculated automatically.
Is aspect-ratio supported in all browsers?+
Yes. Supported in Chrome 88+, Firefox 89+, Safari 15+, and Edge 88+. Universal browser support since 2021.
Does aspect-ratio replace the padding-bottom hack?+
Yes. The padding-bottom percentage trick is no longer needed. aspect-ratio is cleaner, more readable, and doesn't require wrapper elements or absolute positioning.
Try it yourself

Use the CSS Aspect Ratio โ€” free, no signup required.

โšก Open CSS Aspect Ratio
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.