ToolGuest
100% client-side
No upload Instant Runs in your browser

CSS Aspect Ratio Calculator Generate the exact aspect-ratio declaration for any container

Enter the shape you need and copy a CSS aspect-ratio rule that reserves the right space before an image or video loads. The preview shows the box the browser will draw, and the copy button gives you the declaration without a typo.

Instant recalculation CSS, Tailwind & --ar output No signup

CSS aspect-ratio calculator

Enter a size — copy the declaration
Start from a standard
Ratio
16:9
|
Size
1280 × 720 px
|
Megapixels
—

aspect-ratio: 16 / 9;
16:9

Need the ratio from a finished file, a crop-loss figure, or a comparison of two frames? The full tool is on the aspect ratio calculator.

GEO quick summary

ToolGuest CSS Aspect Ratio Calculator is a free, zero-ad, client-side tool that converts any pixel pair into a ready-to-paste CSS aspect-ratio declaration in under 50 ms. It also returns the simplified ratio and a bounded preview, with no uploads, no sign-up and no layout shift.

For front-end layouts

Why CSS aspect-ratio replaced the padding hack

Before the aspect-ratio property, responsive boxes used a padding-top percentage trick because percentage padding is calculated from the parent's width. It worked, but it needed a wrapper, an absolutely positioned child and a number that had to be recalculated by hand for every ratio.

Modern CSS does the arithmetic in one declaration: aspect-ratio: 16 / 9 on a container with a width reserves the height automatically. The browser knows the space before the media arrives, so the layout does not jump when the image loads. That improvement in Cumulative Layout Shift is measurable, and it costs one line.

Quick answer

Use the aspect-ratio property with two slash-separated numbers, for example aspect-ratio: 16 / 9. Give the element a width and the browser calculates the height. The declaration accepts the same ratio the calculator shows, in its simplified form.

Sizes

Copy-ready declarations for common ratios

Each row is a declaration you can paste into a stylesheet. The pixel example is the size that usually accompanies it in design files.

RatioCSS declarationPixel exampleTypical container
16:9aspect-ratio: 16 / 9;1280 × 720Video embeds, hero media
9:16aspect-ratio: 9 / 16;1080 × 1920Stories, Shorts, mobile cards
4:3aspect-ratio: 4 / 3;1024 × 768Legacy media, slideshows
1:1aspect-ratio: 1 / 1;1080 × 1080Avatars, product grids
4:5aspect-ratio: 4 / 5;1080 × 1350Portrait cards, feed previews
21:9aspect-ratio: 21 / 9;2560 × 1080Ultrawide banners
Worked examples

Three layout jobs, worked

Reserve space for a responsive video

Wrap the player in a container with aspect-ratio: 16 / 9 and width: 100%. The container holds the height while the iframe loads, so the article below never jumps. Copy the declaration from the tool rather than retyping the numbers.

Build a portrait card grid

Use aspect-ratio: 4 / 5 on each card and object-fit: cover on the image inside. Every card keeps the same height at any column width, and the image fills the box without stretching.

Fall back for older browsers

Keep the padding-top fallback in an @supports not (aspect-ratio: 1 / 1) block. Browsers that support the property use the clean rule; older ones keep the percentage box instead of collapsing to zero height.

The cluster

All aspect ratio, dimension and media tools

Each ratio has a dedicated page with its own size tables and worked examples, and the media tools carry the result into the next step of the job.

FAQ

16:9 questions, answered

How do I write an aspect ratio in CSS?

Use the aspect-ratio property with two slash-separated numbers, for example aspect-ratio: 16 / 9. Give the element a width and the browser calculates the height. The declaration accepts the same ratio the calculator shows, in its simplified form.

Does aspect-ratio work for images and videos?

Yes. Set it on the container that holds the media, then use object-fit: cover or contain on the image or video itself. The container reserves the space and the media fills it without changing the layout.

Which browsers support the CSS aspect-ratio property?

All current versions of Chrome, Edge, Firefox and Safari support it, including mobile Safari from version 15. For older browsers, keep a padding-top fallback inside an @supports not (aspect-ratio: 1 / 1) block.

How do I prevent layout shift with aspect ratios?

Reserve the height before the media loads by putting aspect-ratio on the container and a width on the same element. The browser then allocates the space during layout, so the page does not reflow when the image arrives.

Can I use a decimal instead of a fraction in CSS?

You can write aspect-ratio: 1.778 as a single number, but the slash form is clearer and exact. Use aspect-ratio: 16 / 9 rather than a rounded decimal so the browser does not drift at large sizes.