CSS // blog
All blog postsHow to Calculate Aspect Ratio for Images, Video, and CSS (Online Tool and Simple Math)
Aspect Ratio Calculator / Image Aspect Ratio CalculatorEvery developer and designer runs into that awkward resize moment sooner or later: you drop an image into a card or embed a video on a landing page, tweak the width to 720px, and suddenly you are squinting at a calculator wondering what height keeps things from looking stretched like taffy.
Skip the fraction headaches. The Aspect Ratio Calculator / Image Aspect Ratio Calculator finds the simplified ratio or the missing width and height in this tab. We never see the files. Copy CSS when you are ready.
Calculate aspect ratio and missing dimensions in seconds
Use it as an image aspect ratio calculator for responsive thumbnails, or as a 16:9 aspect ratio calculator for video embeds. Enter any width and height, or lock a preset like 16:9, 4:3, 1:1, or 9:16, and watch the matching dimensions update live. Paste 16 9, 16 x 9, or 16 by 9. Drop one photo to read its size, or two photos to compare ratios.
Math, preview, and copy stay on your computer. Once the box sizes are locked in, jump to the CSS Grid Generator, the px to rem Converter / rem to px Converter, or the WebP to PNG Converter / PNG to WebP Converter to finish the layout and assets.
What is an aspect ratio (and why it matters)
An aspect ratio is the proportional relationship between an object's width and height, written as two numbers separated by a colon (Width : Height):
| Ratio | Where it shows up |
|---|---|
| 16:9 (widescreen) | YouTube, monitors, and hero banners (1920 x 1080, 1280 x 720). |
| 9:16 (vertical / portrait) | Stories, Reels, Shorts, and phone screens (1080 x 1920). |
| 4:3 (classic display / photo) | Older displays, slides, and some camera sensors (1024 x 768, 1600 x 1200). |
| 1:1 (square) | Avatars, app icons, social tiles, and thumbnails (512 x 512, 1080 x 1080). |
Getting the ratio right keeps images sharp, prevents awkward cropping, and stops Cumulative Layout Shift (CLS), the page jump when an image loads late and pushes text down the screen.
How to calculate aspect ratio by hand
An aspect ratio calculator online is the fastest move when you are mid-sprint. Still, knowing how to calculate aspect ratio by hand, how to solve a missing side, and how to write it in CSS is a useful trick to keep.
1. Find the simplified aspect ratio from width and height
Suppose you have an image that is 1920px wide and 1080px tall, and you want to calculate aspect ratio in simplest form:
- Find the Greatest Common Divisor (GCD) of both numbers (1920 and 1080). The largest number that divides evenly into both is 120.
- Divide both width and height by that GCD: width = 1920 / 120 =
16, height = 1080 / 120 =9. - Write them together:
16:9.
Quick shortcut: if you do not spot the GCD right away, divide both sides by 10, then keep dividing by 2 or 3 until they will not divide evenly anymore. 192 x 108 becomes 96 x 54, then 48 x 27, then 16 x 9.
2. Solve a missing width or height (16:9 example)
Need the height that matches an 800px-wide container on a 16:9 video? Use cross-multiplication:
New height = (new width x ratio height) / ratio width. Plug in 800px at 16:9: (800 x 9) / 16 = 7200 / 16 = 450px.
Flip it if you know the height (450px) and need the width: new width = (new height x ratio width) / ratio height = (450 x 16) / 9 = 800px.
3. Quick JavaScript helper to simplify any ratio
Want to compute ratios inside a front-end script or media uploader? Here is a readable helper using Euclidean GCD:
JavaScript
function gcd(a, b) {
let x = Math.abs(Math.round(a));
let y = Math.abs(Math.round(b));
while (y !== 0) {
[x, y] = [y, x % y];
}
return x || 1;
}
function getAspectRatio(width, height) {
const divisor = gcd(width, height);
return {
ratioWidth: width / divisor,
ratioHeight: height / divisor,
label: `${width / divisor}:${height / divisor}`,
};
}
console.log(getAspectRatio(1920, 1080).label); // "16:9"
console.log(getAspectRatio(1080, 1920).label); // "9:16"4. Practical CSS examples (aspect-ratio + object-fit)
In modern CSS, you rarely need the old padding-bottom hack. Native aspect-ratio keeps responsive boxes clean:
CSS
.video-embed {
width: 100%;
aspect-ratio: 16 / 9;
border-radius: 0.75rem;
overflow: hidden;
}
.card-thumbnail {
width: 100%;
aspect-ratio: 4 / 3;
object-fit: cover; /* Fills the box without stretching */
}Tailwind aspect-video is 16:9. aspect-square is 1:1. The calculator copies those classes when the ratio matches.
5. Common mistakes that warp layouts
- Mixing up 16:9 and 9:16. 16:9 is landscape (wider than tall). 9:16 is portrait (taller than wide). Swapping them turns a banner into a skyscraper. Load those presets on the same page instead of chasing a separate 16 9 aspect ratio calculator URL.
- Forgetting
object-fit: coveron images. Settingaspect-ratio: 16 / 9on animgwithout cover can squish photos whose natural ratio does not match the container. - Odd decimal pixels. When scaling unusual widths, rounding to whole pixels (
Math.round(...)) avoids blurry sub-pixel edges on crisp UI thumbnails.
Calculate aspect ratio online in seconds, resize an asset with the image aspect ratio calculator, or run the 16:9 math yourself. The Aspect Ratio Calculator / Image Aspect Ratio Calculator stays on your computer. We never see the files.
Share