The CSS <object-fit> property allows us to control how an image or video fits into its container. This is especially important when the element’s size differs from its original aspect ratio.
The <object-fit> property sets how an image should fit into a box of defined width and height. The most common values are cover and contain.
The following examples show how the same image behaves with different object-fit values.
Cover fills the container by cropping the image, while contain keeps the entire image but may leave empty space in the container.
Object-fit is particularly useful for responsive design, but user experience should be considered.
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.