CSS aspect-ratio generator — keep video and image boxes in shape

Enter a ratio in almost any form, from 16:9 to 1920x1080 or 2.39, and the tool simplifies it, writes the aspect-ratio CSS, and gives the matching padding-top percentage for an optional fallback.

Live demo · real result from this tool
Write 16:9, 16/9, 1920x1080 or a single number such as 2.39.

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the CSS aspect ratio generator

  1. Type the Ratio. You can write 16:9, 16/9, 1920x1080, 1920×1080 or a single number such as 2.39.
  2. Keep Include the padding-top fallback ticked if you need support for very old browsers.
  3. Read the Simplified ratio, the Decimal (width ÷ height) and the Height as % of width.
  4. Copy the .media rule, or pick a ratio from the Common ratios table.

What it does and when to use it

aspect-ratio keeps a box in shape while its width changes. Use it for responsive video embeds, image placeholders that reserve space before the picture loads (which stops the page from jumping), square avatar tiles, portrait product cards and full-width cinema-style banners.

When the box holds an image or video, combine it with the object-fit generator so the media fills the shape without distortion. To get an image file at the exact ratio, use the image cropper, and for a grid of equal tiles, the CSS grid generator.

How it works

The tool reads two numbers (or one, with a height of 1) and reduces them. Decimal ratios are scaled up first, so 2.39 becomes 239 / 100. It then writes:

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

With the fallback ticked, it adds an @supports not (aspect-ratio: 1) block that uses padding-top: <height ÷ width × 100>% and stretches the child with position: absolute; inset: 0. MDN lists @supports as Baseline widely available since September 2015.

Worked examples

Widescreen video. 16:9 gives aspect-ratio: 16 / 9;, decimal 1.7778, and padding-top: 56.25%; in the fallback.

A portrait social post. 1080x1350, fallback off: the simplified ratio is 4:5, decimal 0.8, and the CSS is aspect-ratio: 4 / 5;. The box is 125% as tall as it is wide.

A typo. abc returns “Enter a ratio such as 16:9, 4/3, 1920x1080 or 2.39.”

Common ratios

The tool lists these ratios with their CSS and fallback values:

Use aspect-ratio Padding fallback
Square 1 / 1 100%
Portrait photo 4 / 5 125%
Classic TV / photo 4 / 3 75%
35 mm photo 3 / 2 66.667%
Widescreen video 16 / 9 56.25%
Vertical video 9 / 16 177.778%
Ultra-wide (21:9) 7 / 3 42.857%

Limits and tips

  • Ratios only, no sizes. Set width or max-width yourself; the generated width: 100% fills the parent.
  • A fixed height wins. If you also set both width and height, aspect-ratio is ignored.

Frequently asked questions

What does aspect-ratio actually do?
It gives an element a preferred width-to-height shape. When only the width is set, as in the generated width 100%, the browser works out the height from the ratio, so a video box stays 16:9 at every screen size.
Why does 1920x1080 become 16 / 9?
The tool divides both numbers by their greatest common divisor, 120 in this case. The shape is the same, and the short form is easier to read.
What is the padding-top fallback?
Before aspect-ratio existed, the usual trick was a zero-height box with padding-top as a percentage, because vertical padding percentages are based on the width. 56.25% is 9 ÷ 16. The child is then absolutely positioned to fill it.
Do I still need the fallback?
Probably not for current browsers. MDN lists aspect-ratio as Baseline widely available since September 2021. Keep the fallback only if your audience includes very old browsers; it sits inside @supports not, so modern browsers ignore it.
Does aspect-ratio stretch my content?
It sets the box shape, not the content. If text inside needs more room than the ratio allows, the box grows taller. For images and videos, add object-fit to control how they fill the box.

Sources

  1. aspect-ratio - CSS | MDN — MDN Web Docs, accessed 2026-10-08
  2. @supports - CSS | MDN — MDN Web Docs, accessed 2026-10-08

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close