property

object-fit — CSS reference

Controls the concrete size of the object inside a replaced element’s content box. Initial fill; not inherited. Contain and cover preserve a natural aspect ratio but differ in whether the whole object is visible. The property does not set the element’s own width or height.

Formal Syntax & Structure

css syntaxcss
fill | contain | cover | none | scale-down (Level 3 values)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS sizing and overflow lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#a{width:100px;height:100px;object-fit:contain}</style><body><img id="a" alt="Teal rectangle" src="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27120%27 height=%2760%27%3E%3Crect width=%27120%27 height=%2760%27 fill=%27teal%27/%3E%3C/svg%3E"></body></html>
CSS Reference