CSS object-fit

object-fit is a CSS property that specifies how an <img> or <video> should be resized to fit its container. This property is useful when you want to control how an image or video is displayed within its container. There are several values that you can use with the object-fit property:

Let's see some examples of how you can use the object-fit property:

Result:

Using object-fit: fill;

In the example above, we have an image that is resized to fill its container using the fill value for object-fit.

Result:

Using object-fit: cover;

In this example, we have a video element that is resized to maintain its aspect ratio while filling the container's entire content box using the cover value for object-fit.

Experiment with different values for object-fit to see how they affect the sizing and display of images and videos within their containers!