CSS aspect-ratio Property

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The aspect-ratio property sets the preferred width-to-height ratio of a box. Write 16 / 9 and, if the width is known and the height is auto, the browser calculates the height. The ratio is width divided by height.

The initial value is auto. It is not inherited. One side must stay automatic, or the ratio does not change the used size. It applies to elements except inline boxes and internal table or ruby boxes. A ratio can be animated when one side stays automatic.

Standard-track.

Not deprecated and not experimental. It has been widely available since September 2021: Chrome 88, Firefox 89, and Safari 15. Internet Explorer does not support it.

CSS Syntax

A ratio, the keyword auto, or both. The first number is the width. The second is the height.

syntax.css
aspect-ratio: auto | 16 / 9 | 1 | auto 16 / 9 | initial | inherit;

Property Values

ValueDescriptionTry it
autoInitial. No preferred ratio, unless the element has a natural one, such as a loaded imageTry it
16 / 9Preferred width / height. 1 / 1 is a square. Use any two numbers from 0 upTry it
1Same as 1 / 1. The missing height is 1. 0.5 means 0.5 / 1, so the box is twice as tall as it is wideTry it
auto 16 / 9Use 16 / 9 until a replaced element has its own ratio, then use that ratio. Order does not matterTry it
initialSets this property to its default value, autoTry it
inheritCopies the parent's ratio only. Width and height are not copiedTry it

unset equals initial here, so it is auto. revert is the user-agent value, also auto. A ratio with a 0, such as 1 / 0, is degenerate and behaves as auto. If both width and height are lengths, the ratio does not change the used size.

How to Use aspect-ratio

Give the box one size. Let the ratio calculate the other.

  1. Set width, or let the box stretch across its container. Leave height at auto.
  2. Set aspect-ratio to width / height, such as 16 / 9 or 1 / 1.
  3. If you also set height to a length, the ratio no longer changes the used size. Remove one of the two lengths.
  4. On an image, auto 16 / 9 holds that frame until the file's own ratio is known.
PieceRequired?Role
One automatic sideYesThe ratio fills in the missing side
16 / 9The ratioWidth divided by height
Both sides as lengthsBlocks the ratioThe used size stays at those lengths
auto plus a ratioImagesPlaceholder ratio, then the file's own ratio

Live Preview

The box width stays 10rem. Only the ratio changes, so the height follows. auto lets the text set the height.

Width is fixed. Height is auto, so the ratio can calculate it.

Preview
1 / 1

aspect-ratio: 1 / 1

CSS Examples

Each box has a width and an automatic height. The line to study is aspect-ratio. Use Try It Yourself for a live editor.

Example 1 — Square and 16 / 9

Same width. The ratio chooses the height.

CSS
<style>
  div {
    width: 10rem;
    background: #1d4ed8;
    color: #fff;
  }
  .square { aspect-ratio: 1 / 1; }
  .wide { aspect-ratio: 16 / 9; }
</style>

<div class="square">1 / 1</div>
<div class="wide">16 / 9</div>
Try It Yourself

How It Works

  1. One known side. Both boxes are 10rem wide. Height is left at auto, so the ratio is allowed to set it.
  2. 1 / 1 is a square. Width and height match, so the box is 10rem tall.
  3. 16 / 9 is wider than it is tall. Height is width × 9 / 16, about 5.6rem.
  4. The first number is the width. 9 / 16 would flip the box and make it tall.

Example 2 — Both Sizes Set

A length for width and a length for height leave the ratio nothing to calculate.

CSS
<style>
  div {
    width: 10rem;
    background: #1d4ed8;
    color: #fff;
  }
  .free { aspect-ratio: 1 / 1; }
  .locked {
    height: 4rem;
    aspect-ratio: 16 / 9;
  }
</style>

<div class="free">1 / 1</div>
<div class="locked">Locked</div>
Try It Yourself

How It Works

  1. The free box has one length. Width is 10rem and height is auto, so 1 / 1 makes a 10rem square.
  2. The locked box has two lengths. Width is 10rem and height is 4rem.
  3. 16 / 9 does not resize it. That ratio would want a height near 5.6rem. The used height stays 4rem.
  4. The property is still set. Computed style can show 16 / 9 even while the used size ignores it. Drop the height if you want the ratio to win.

Example 3 — A Single Number

If you omit the slash, the height is 1.

CSS
<style>
  div {
    width: 8rem;
    background: #1d4ed8;
    color: #fff;
  }
  .one { aspect-ratio: 1; }
  .half { aspect-ratio: 0.5; }
</style>

<div class="one">1</div>
<div class="half">0.5</div>
Try It Yourself

How It Works

  1. A single number is width / height. The missing second number is 1.
  2. 1 is 1 / 1. The box is a square, 8rem by 8rem.
  3. 0.5 is 0.5 / 1. Width is half the height, so the box is 8rem wide and 16rem tall.
  4. It is not half a square. 0.5 does not mean "half the height." It means the width is half the height.

Edge Cases & Pitfalls

size

Two lengths block the ratio

If width and height are both lengths, the used box keeps those sizes. min-height, max-height, min-width, and max-width also win when they conflict with the ratio.

flex

A stretched flex item blocks the ratio

In a row flex container, align-items: stretch can set the height. Both sides are then definite, so the ratio does not change the box. align-self: flex-start leaves the height automatic.

auto

auto with a ratio follows the image

aspect-ratio: auto 3 / 2 holds 3 / 2 only until a replaced element has a natural ratio. A loaded image then uses its own ratio. A div has none, so it stays 3 / 2. object-fit sizes the picture inside the box. It is a different property.

box

The ratio follows box-sizing

With content-box, the ratio is the content box. Padding and border sit outside it. With border-box, padding and border are inside the ratio.

inline

Inline boxes ignore it

An inline span does not take a ratio. Set display to block or inline-block. Internal table and ruby boxes are excluded too.

0

Zero and negative numbers

A negative number is invalid, so the declaration is dropped. A 0 on either side is a degenerate ratio and behaves as auto.

Browser Support

aspect-ratio is a browser sizing property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Since Sep 2021

aspect-ratio

Chrome 88+, Edge 88+, Firefox 89+, Safari 15+, Opera 74+, and Samsung Internet 15+. No support in Internet Explorer.

96% Modern browser support
Google Chrome 88+
Full support
Mozilla Firefox 89+
Full support
Apple Safari 15+
Full support
Microsoft Edge 88+ · Chromium
Full support
Opera 74+
Full support
Samsung Internet 15+
Full support
Internet Explorer Not supported
Not supported
aspect-ratio Widely supported

Bottom line: Safe in current Chrome, Edge, Firefox, Safari, Opera, and Samsung Internet. It has been baseline since September 2021, when Safari 15 shipped. Internet Explorer ignores it, so a fixed width and height is the fallback there.

Key Takeaways

  • Role: preferred width / height. One automatic side is what the ratio fills in.
  • Default: auto. A div has no preferred ratio. An image uses its natural one.
  • Numbers: 16 / 9 is width / height. 1 means 1 / 1. 0.5 is a tall box.
  • Blocked: two lengths, min and max sizes, and inline boxes. The property is not inherited.

One line: aspect-ratio keeps width / height, as long as one side is left automatic.

Frequently Asked Questions

It sets a preferred width-to-height ratio. If one side is automatic, the browser calculates the other side so the box keeps that ratio.
The initial value is auto. A normal box then has no preferred ratio. A replaced element, such as an image, uses its own natural ratio. The property is not inherited.
Both width and height are already lengths. The ratio only fills in an automatic side. Set one side, such as width: 10rem, and leave the other at auto.
16 / 9 is about 1.777. A single number is width divided by height, and the missing height is 1. So 1 is a square, and 0.5 is twice as tall as it is wide.
The 16 / 9 ratio is used until the image has a natural ratio. After the file loads, auto switches to that natural ratio. A plain div has no natural ratio, so it keeps 16 / 9.
Chrome 88+, Edge 88+, Firefox 89+, Safari 15+, Opera 74+, and Samsung Internet 15+. It has been a baseline feature since September 2021. Internet Explorer does not support it. Node.js, Deno, and Bun do not apply it.

Next: backdrop-filter

Blur or tint whatever sits behind an element.

backdrop-filter tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful