Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The aspect-ratio property

Reference for the CSS aspect-ratio property: ratio syntax, auto, how it combines with width and height, examples for cards and video, and browser support.

The aspect-ratio property gives a box a preferred width-to-height ratio. When one dimension is known and the other is auto, the browser computes the missing one from the ratio. It replaces the old "padding-top percentage" trick for responsive thumbnails, video frames and square avatars.

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

Try it

Ratios that follow the width
Ratio versus content

The second box is taller than a square because min-height: auto lets content push the box open. The third box has a definite height, so the ratio no longer applies.

Syntax

CSS
aspect-ratio: auto || <ratio>

/* examples */
aspect-ratio: 16 / 9;
aspect-ratio: 1;
aspect-ratio: auto 4 / 3;
  • Initial value: auto
  • Applies to: all elements except inline boxes and internal ruby or table boxes
  • Inherited: no
  • Animatable: yes, as a number (interpolated between ratios)
  • Computed value: the keyword auto plus a <ratio> if specified

Values

Value Description
auto Replaced elements (images, video, canvas) use their intrinsic ratio. Other boxes have no preferred ratio.
<ratio> Width divided by height, written 16 / 9 or as a single number such as 1.5. A lone number 1 means a square. The spaces around / are optional.
auto <ratio> Uses the intrinsic ratio of a replaced element if it has one, and falls back to the given ratio otherwise. Handy for images that have not loaded yet.

Usage notes

  • Needs one free dimension. The ratio only fills in an auto size. If both width and height are definite, the ratio is ignored.
  • Content can win. For non-replaced boxes the ratio sets the preferred size; if the content does not fit, the box grows. Set min-height: 0 plus overflow to enforce a strict shape, or use overflow: hidden.
  • Images. Setting aspect-ratio together with object-fit: cover crops an image to a consistent frame. Adding width and height attributes on <img> also lets the browser reserve space and avoid layout shift.
  • Embeds. An <iframe> has no intrinsic ratio, so aspect-ratio: 16 / 9; width: 100%; height: auto is the usual way to size a video embed.
  • Flex and grid. Items can use aspect-ratio too, but stretch alignment may override the computed size; set align-self: start if needed.
  • Invalid ratios. A zero or negative ratio, or 0 / 1, is invalid and the declaration is dropped.

Browser support

Baseline since 2021 and supported in all current major browsers; only very old browsers need the padding-top fallback.