
The aspect-ratio property sets the proportions of a box. Give an element a width, and the browser works out the height for you:
aspect-ratio: 16 / 9;
That one line replaced the old “padding-top: 56.25%” hack for responsive videos, and it’s the easiest way to make square thumbnails, card images and placeholders that keep their shape at every screen size.
Demo:
<div class="ar-demo">
<div class="ar-demo__box" style="aspect-ratio: 1">1 / 1</div>
<div class="ar-demo__box" style="aspect-ratio: 4 / 3">4 / 3</div>
<div class="ar-demo__box" style="aspect-ratio: 16 / 9">16 / 9</div>
<div class="ar-demo__box" style="aspect-ratio: 3 / 4">3 / 4</div>
</div>.ar-demo {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
gap: 16px;
align-items: start;
padding: 20px;
border-radius: 16px;
background: #f1f5f9;
font: 600 14px/1 ui-monospace, monospace;
}
.ar-demo__box {
display: grid;
place-items: center;
border-radius: 12px;
background: linear-gradient(135deg, #3b82f6, #1e3a8a);
color: #fff;
}Every box is the same width, set by the grid. aspect-ratio alone decides each height, and the ratios hold as you resize the window.
Common uses
Responsive video embeds
YouTube and Vimeo iframes have a fixed size by default. Make them fluid and keep them 16:9 with two lines.
iframe.video {
width: 100%;
height: auto;
aspect-ratio: 16 / 9;
}
/* The old way, no longer needed */
.video-wrapper {
position: relative;
padding-top: 56.25%; /* 9 / 16 */
}
.video-wrapper iframe {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}Square or portrait images with object-fit
Force any image into a ratio, and use object-fit: cover so it fills the box and crops the overflow instead of stretching. Perfect for avatars, product grids and card thumbnails that come in different sizes.
.thumb {
width: 100%;
aspect-ratio: 1; /* same as 1 / 1 */
object-fit: cover;
object-position: center; /* which part to keep */
border-radius: 12px;
}
.avatar {
width: 48px;
aspect-ratio: 1;
object-fit: cover;
border-radius: 50%;
}Equal card images in a grid
Combined with a responsive CSS Grid, every card image lines up, whatever size the original photos are.
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 24px;
}
.card img {
width: 100%;
aspect-ratio: 3 / 2;
object-fit: cover;
}Avoiding layout shift
Set width and height on images
Browsers already use aspect-ratio for images: when an <img> has width and height attributes, the browser reserves the right space before the image loads, so the text below doesn’t jump. Keep the attributes, and let CSS make the image responsive. This directly improves Cumulative Layout Shift, one of the Core Web Vitals (more in web performance).
<img src="photo.jpg" width="1200" height="800" alt="...">
<style>
img {
max-width: 100%;
height: auto; /* keeps the 1200:800 ratio while scaling */
}
</style>Placeholders for content that loads later
Reserve the space for embeds, ads and lazy-loaded media, so nothing moves when they arrive.
.embed-placeholder {
width: 100%;
aspect-ratio: 16 / 9;
background: #e2e8f0;
}Why aspect-ratio seems to be ignored
- Both width and height are set. The ratio only applies when at least one dimension is
auto. Remove the fixed height. - The content is taller than the ratio allows. By default, a box with text grows to fit its content (
min-height: auto). Setmin-height: 0plusoverflow: hiddenorautoto force the ratio. - A flex or grid item is being stretched.
align-items: stretchsets the height, overriding the ratio. Usealign-items: start(as in the demo) oralign-self: start. - The element is inline. Like width and height, it doesn’t apply to plain inline elements such as
<span>.
Common ratios
| Ratio | Used for |
|---|---|
1 / 1 |
Avatars, Instagram posts, product thumbnails |
4 / 3 |
Classic photos, older screens |
3 / 2 |
DSLR photos, blog cards |
16 / 9 |
Video, YouTube, presentations |
1.91 / 1 |
Open Graph social images (1200 × 630) |
9 / 16 |
Stories, Reels, Shorts |
2 / 3 |
Pinterest pins, posters |
FAQ
What does aspect-ratio do in CSS?
It sets a preferred width-to-height ratio for a box. When one dimension is known, the browser calculates the other from the ratio.
How do I make a responsive 16:9 video?
iframe { width: 100%; height: auto; aspect-ratio: 16 / 9; }. No wrapper or padding hack needed.
Is aspect-ratio supported in all browsers?
Yes, all current browsers have supported it since 2021.
Can I use decimals in aspect-ratio?
Yes. aspect-ratio: 1.5 is the same as 3 / 2, and a single number means “width divided by 1”.
Related: CSS Grid, web performance, CSS triangles and CSS transform.





