🎨 Fix aspect-ratio Ignored on a Replaced Video Element
The CSS aspect-ratio property only controls an element’s box sizing when at least one of width or height is left to resolve automatically, and a <video> element carries its own intrinsic aspect ratio from the media file itself — when both the element’s CSS width and height are set explicitly (common when a layout grid forces both dimensions), that explicit sizing wins outright, and the aspect-ratio declaration has nothing left to influence at all.
🔎 The Problem
video.player {
width: 100%;
height: 400px; /* explicit, fixed height */
aspect-ratio: 16 / 9; /* has no effect - both dimensions already set */
}
/* Video stretches or letterboxes inside the fixed 400px height
instead of actually maintaining 16:9 */
✅ Fix: Leave One Dimension for aspect-ratio to Actually Control
- Set only the width explicitly (
width: 100%) and letheight: autocombine withaspect-ratioto compute the height, since the property needs exactly one free dimension to have any effect. - If a fixed-height layout slot is unavoidable, wrap the video in a container sized to the aspect ratio instead, and have the video itself use
width: 100%; height: 100%; object-fit: coverinside that container. - Check computed styles in DevTools when aspect-ratio ‘isn’t working’ — if both width and height show as explicit pixel values rather than one showing
auto, that confirms this is the cause rather than a browser support issue.
Aspect-ratio doesn’t override an explicit size — it only steps in for the dimension you left for it to fill.




