The Mathematics of Aspect Ratios: How Euclidean GCD and Modern CSS Eliminated the 56.25% Hack
If you worked in frontend web development prior to 2021, you almost certainly wroteβor copy-pastedβthis grotesque snippet of CSS into a production stylesheet:
/* THE LEGACY PADDING-BOTTOM HACK */ .video-container { position : relative ; width : 100% ; height : 0 ; padding-bottom : 56.25% ; /* 9 divided by 16 = 0.5625 */ }
.video-container iframe , .video-container video { position : absolute ; top : 0 ; left : 0 ; width : 100% ; height : 100% ; }
Enter fullscreen mode
Exit fullscreen mode
For more than a decade, this was the industry-standard technique for making an embedded YouTube video or canvas element maintain a 16:9 widescreen ratio without collapsing into zero height.
Because the CSS specification historically calculated percentage padding relative to the width of the containing block, frontend engineers exploited this quirk by setting height: 0 and driving vertical layout space purely through bottomβ¦