25
loading...
This website collects cookies to deliver better user experience
object-fit
property determines how the content of a replaced element is resized to fit inside its container on a web page.<img>
tag. We can specify the position of the image, but we can't actually influence the contents of the image displayed inside the <img>
tag using CSS.object-fit
property to influence how an image is resized to fit inside its container element (i.e. the img
tag).<img>
are: <embed>
, <iframe>
and <video>
. This page on MDN has more information about replaced elements.<img>
tags with a width and height of 200px
and see how the various object-fit
property values affect how the images are resized. I have given the <img>
tag a gray border so that its edges are easy to identify.object-fit
CSS property is used on the <img>
tag.object-fit
property. With this value, the image inside an <img>
tag will be resized to the size of the container (i.e. the <img>
tag).<img>
tag aren't the same, the image will be stretched.<img>
tag, then there will be a portion of the container that doesn't contain the image.object-fit: contain
:object-fit
property has either the value none
or the value contain
depending on which one results in a smaller image.object-fit: none
) and images that are bigger than the container size are resized to fit the container (like with object-fit: contain
).