CSS Object Fit
CSS
What is object-fit?
The object-fit property defines how the content of a replaced element (like <img> or <video>) should fit within its box, especially when the aspect ratio doesn’t match.
- It works like background-size for images/videos.
Common Syntax
| Value | Description |
|---|---|
| fill | Stretches the image to fill the box. May distort it. |
| contain | Resizes the image to fit entirely in the box. Keeps aspect ratio. |
| cover | Image fills the box, may crop edges. Keeps aspect ratio. |
| none | Image keeps its original size, overflows if bigger than the box. |
| scale-down | Chooses the smaller of none or contain |