Aspect ratio calculator

Turn any width and height into a reduced ratio, a decimal and the Tailwind class, resize to a new width while keeping the shape, and copy the aspect-ratio rule that reserves the space before the image loads.

Preset
Ratio
Decimal
Tailwind
Height at that width
aspect-ratiocss
/* CSS */
.media {
  aspect-ratio: 16 / 9;
}

/* Tailwind */
<div className="aspect-video">

/* Decimal */
1.778
Prefer the CSS property over the old padding-bottom trick: it reserves the space before the image arrives, so nothing jumps, and it works on any element, not only on a wrapper with an absolutely positioned child.
Made something you like?Gallery blocks that use it

Questions

Which is better, aspect-ratio or padding-bottom?+

The property. The padding trick needs a wrapper with an absolutely positioned child and only works because padding percentages are relative to width. aspect-ratio applies to any element, keeps working when a min-height is set, and every current browser supports it.

Why does Tailwind have aspect-video but not aspect-4/3?+

Only 16:9 and 1:1 are common enough to earn a name. Everything else is an arbitrary value, aspect-[4/3], which compiles to the same property. The tool prints the named class when one exists and the arbitrary form otherwise.

How does the tool reduce 1920 by 1080 to 16:9?+

By the greatest common divisor, the same way you would by hand. Dimensions with decimals are rounded to the nearest thousandth first so the ratio stays small enough to read.

Related tools

The tools are free. So is most of the library.

2095 blocks and 1076 pieces for shadcn/ui and Tailwind, built on the same tokens these tools write. Install one with a command and the code is yours.

No signup for the tools. MIT for free blocks, commercial licence for Pro.

Markdown version