b2KIT

CSS Aspect Ratio Calculator

Calculate and preview CSS aspect-ratio values with common presets and responsive container sizing.

Tested tool guide Tested browser tools Checked August 15, 2026

What CSS Aspect Ratio Calculator does, with a checked example

Enter a pixel width and height, or pick a preset like 16:9, 4:3, 1:1, or 21:9, and the tool reduces the pair to its lowest integer ratio using the greatest common divisor, then writes the resulting aspect-ratio: w / h; declaration. A live preview box demonstrates how that ratio holds as its container width changes. The thing people most often get wrong: aspect-ratio is a sizing hint, not a hard constraint. It only takes effect when at least one used dimension is auto; an element with both width and height explicitly set has no auto dimension left for the ratio to fill, and layout contexts that resolve both dimensions through other means, such as stretch alignment in a flex or grid parent, can similarly leave no room for the ratio to apply.

Worked example

A concrete input and expected output from the current implementation.

Input

1920x1080

Expected output

aspect-ratio: 16 / 9;

1920 and 1080 share a greatest common divisor of 120; dividing both by 120 reduces the pair to the lowest-terms ratio 16:9, which becomes the CSS value.

How the result is produced

1

Ratio reduction via GCD

The tool runs the Euclidean algorithm on the two numbers you enter to find their greatest common divisor, then divides both by it to reach the lowest-terms ratio: 1920x1080 becomes 16:9, 800x600 becomes 4:3. That reduced pair is written directly into the aspect-ratio: width / height; declaration, so the output CSS is never left as an unreduced fraction.

2

Resizable preview box

A sample container is rendered with the resulting aspect-ratio value applied and only its width constrained; the browser's own layout engine computes the height. Dragging the preview wider or narrower shows exactly how the ratio holds at arbitrary sizes, which reflects real rendering behavior rather than a separately simulated calculation.

Good uses

  • Setting up a responsive video or image embed when you know the source file's pixel dimensions and need the matching CSS ratio without doing the division by hand
  • Checking whether an odd-looking pair of numbers, like a screenshot at 1900x1187, reduces to a clean named ratio or something closer to an unusual fraction before hardcoding it
  • Prototyping a thumbnail or card grid and testing how a chosen ratio behaves at several container widths before writing the layout CSS by hand

Limits and checks

  • The reduction always finds the exact greatest common divisor, so the math is never wrong, but if the source numbers are off by even a pixel (1919x1080 instead of 1920x1080) the GCD can drop to 1, leaving a large, unrecognizable fraction like 1919/1080 printed as-is instead of a clean preset like 16/9
  • aspect-ratio only takes effect when it can resolve an auto dimension; a flex or grid parent whose stretch alignment resolves an item across both axes, or a competing explicit width-and-height pair, can leave no auto dimension for it to fill in ways the static preview cannot reproduce. A lone explicit height with width still auto does not override it - the browser derives the width from the ratio instead
  • The tool does not check or report browser support; aspect-ratio is unsupported in older engines (pre-2021 Safari and Firefox releases), and it does not generate a padding-top percentage fallback for those cases

Common questions

Why doesn't the preview match what I see when I paste this into my actual page?

aspect-ratio is a sizing hint, not a forced constraint. Competing explicit width and height, min/max constraints, or a flex/grid parent that resolves both dimensions through stretch alignment can leave no auto dimension for it to fill in your real layout, while the tool's preview box has no such competing rules and always shows the ratio applied cleanly.

Does this generate a fallback for browsers that don't support the aspect-ratio property?

No. It outputs only the aspect-ratio declaration. For older browser support you would need to add the padding-top percentage hack or a JavaScript polyfill separately; this tool does not produce that fallback code.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools