CSS aspect-ratio Property (No Padding Hack)

Aspect ratios without the padding hack

The old trick used padding-top: 56.25% and nested absolute positioning. aspect-ratio does it in one declaration.

Old way 8 lines
.video-wrapper   {  position: relative;  padding-top: 56.25%;}.video-wrapper > *   {  position: absolute;  top: 0;  left: 0;  width: 100%;  height: 100%;}
2 lines
.video-wrapper   {  aspect-ratio: 16 / 9;}
Widely available Since 2021 93% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2021.

Safe to use without fallbacks.

88+
89+
15+
88+
different aspect ratios with one property
1 / 1
16 / 9
3 / 4

No math

16/9, 4/3, 1/1. No percentage math or nested wrappers.

Single element

One container, one property. Content can sit inside without absolute positioning.

Any ratio

Use any ratio you need. Works with flex and grid too.

Lines Saved
8 → 2
75% less code
Old Approach
Padding + absolute
56.25% for 16:9
Modern Approach
One property
aspect-ratio: 16/9

How it works

The classic trick was a wrapper with padding-top: 56.25% (100/16*9 for 16:9) and position: relative, then a child with position: absolute; inset: 0 to fill it. Two selectors, magic numbers, and the child had to be taken out of flow.

aspect-ratio: 16 / 9 on the container does the job. The element keeps that ratio as width changes. No padding hack, no absolute child, no percentage math.

ESC