object-fit controls replaced media fitting inside a fixed box.
Key values
coverfills box with crop risk.containshows full media with potential empty space.fill,none,scale-downfor edge cases.
Important interview questions and answers
- Q: Why is
covercommon in cards?
A: Consistent tile framing across mixed source dimensions. - Q: When prefer
contain?
A: When full asset visibility matters more than edge-to-edge fill. - Q: Does object-fit affect background images?
A: No, it applies to replaced elements likeimg/video.
Practice: Change one property in the playground and observe cascade + layout in DevTools.