objectfit
Object-fit is a CSS property that defines how the content of a replaced element should be resized to fit its content box. Replaced elements include resources such as images, videos, canvas, and iframes. The property determines how the element’s intrinsic aspect ratio is preserved when its box has different dimensions from the content.
- fill: the content is stretched to fill the entire box, which may distort the aspect ratio.
- contain: the content is scaled to fit inside the box while preserving aspect ratio; the entire
- cover: the content is scaled to fill the box while preserving aspect ratio; some parts may be
- none: no resizing is performed beyond preserving the element’s intrinsic size.
- scale-down: the content is scaled down as if by contain or shown at its intrinsic size, whichever
Usage considerations include alignment and cropping. Object-fit works in conjunction with object-position to control how the
Browser support and fallbacks: object-fit is supported in all major modern browsers, but not in older ones
Overall, object-fit provides a concise way to manage how visual media fills its container, reducing distortion