Reference guide · html-css-js · Published 2026-08-16 · 3 min read

CSS aspect-ratio sizing

CSS aspect-ratio property explained: intrinsic ratio, images and iframes, CLS prevention, and how it differs from aspect-box.

What aspect-ratio does

The CSS aspect-ratio property sets a preferred width-to-height ratio for a box. Combined with one definite dimension, the box sizes the other dimension from the ratio. The flagship use is media: an image or video that has not loaded yet gets the space it will occupy, instead of the page reflowing when it arrives. This is a direct fix for the layout shift that images cause, alongside the image aspect ratio article's HTML-side approach.

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

With width: 100% the box computes height from the ratio. Without a definite width, the box uses its natural width; with aspect-ratio: auto, the preferred ratio falls back to the replaced element's intrinsic ratio (an actual image with width="400" height="300" has an intrinsic ratio of 4/3).

The interaction with auto and intrinsic ratios

The exact resolution rule (per the CSS sizing spec) is what trips people up:

The practical consequences for layout:

img.hero {
  width: 100%;
  aspect-ratio: 16 / 9;   /* reserves space before the image arrives */
  object-fit: cover;      /* crops overflow instead of distorting */
}

The object-fit article covers the crop side; ratio plus object-fit is the pair that stops both the shift and the squish.

Where it removes layout shift

The two classic shifts: images without width/height attributes on an article body, and embeds (YouTube, maps) where the iframe occupies zero space until it loads. For both:

.video-wrap {
  aspect-ratio: 16 / 9;
}

An empty wrapper with a definite ratio and a loaded iframe keeps the page height stable. Fonts load late and change height too; that is covered by font loading and the CLS guide tracks the measured impact.

Gotchas

The image layout-shift guide is the image-specific companion, and the CSS box model article explains how height and width interact with the box it sizes.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services