Eskillsfy

Home / Blog / Web and CSS

Web and CSS · 23 Nov 2026

Aspect Ratio Calculator: how it works and how to build one

Find the ratio of a size, or a missing width or height. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Enter width and height to get the simplest ratio (like 16:9), or lock a ratio and type a new width to get the matching height. Presets for video, photos, social posts and screens.

When to use it

  • Video and thumbnail sizes
  • Responsive images and embeds
  • Print layouts

How to use it

  1. Enter a size or pick a ratio.
  2. Change the width or height.
  3. Copy the new size or CSS aspect-ratio.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/aspect-ratio-calculator

How it works

The ratio of a size is width:height reduced by their greatest common divisor (GCD), found with Euclid’s algorithm. 1920 and 1080 share 120, so the ratio is 16:9.

With a locked ratio, a new width gives height = width × h ÷ w.

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

ratio.ts (ts)

const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);

export const ratio = (w: number, h: number) => { const g = gcd(w, h); return `${w / g}:${h / g}`; };
export const heightFor = (width: number, rw: number, rh: number) => Math.round((width * rh) / rw);

ratio(1920, 1080);       // "16:9"
heightFor(1280, 16, 9);  // 720
// CSS: aspect-ratio: 16 / 9;

Make it production-ready

  • Snap odd sizes to the nearest common ratio.

Questions

What is 1920 × 1080?

16:9, the standard for HD video, YouTube and most screens.

Try the Aspect Ratio Calculator

Free, runs in your browser, nothing is uploaded.

Open it
Keep reading

More in Web and CSS

All posts