aspect-ratio + object-fit Playground

Write aspect-ratio and object-fit and see the box the browser measures: the cropped part of the photo, the empty room, the ignored ratio. An interactive…

Why it matters

Before 2021, a responsive 16:9 video needed the "padding-top hack". Now it is one line. Add object-fit, and a photo of any ratio fits a box of any ratio without squashing.

The key idea

aspect-ratio works out the auto side, object-fit places the content

Common mistakes

Try it in this playground