CSS Object-fit Property

The object-fit CSS property sets how the content of a replaced element, such as an <img> or <video>, should be resized to fit its container.

You can alter the alignment of the replaced element’s content object within the element’s box using the object-position property.


fill: This is default. The replaced content is sized to fill the element’s content box. If necessary, the object will be stretched or squished to fit

contain: The replaced content is scaled to maintain its aspect ratio while fitting within the element’s content box

cover: The replaced content is sized to maintain its aspect ratio while filling the element’s entire content box. If the object’s aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.

none: The replaced content is not resized.

scale-down: The content is sized as if none or contain were specified, whichever would result in a smaller concrete object size.

See the Pen
CSS Object fit property demo
by Carles Rider (@carlesrider)
on CodePen.light

Leave a Reply

Your email address will not be published. Required fields are marked *