Open In App

What is the purpose of the object-fit Property?

The object-fit property in CSS is used to control how an image or replaced element should be resized and fitted within its container. It allows you to specify whether the content should maintain its aspect ratio, be stretched, or fill the container while preserving its intrinsic proportions.

Note: The object-fit property can take values such as fill, contain, cover, none, or scale-down.

Syntax:

/* Ensuring that an image completely covers its container */
img {
object-fit: cover;
}

Features

Article Tags :