Object fit

Utilities for controlling how an image or video is resized to fit its container.

On this page
ClassProperties
.object-containobject-fit: contain;
.object-coverobject-fit: cover;
.object-fillobject-fit: fill;
.object-noneobject-fit: none;

Usage

Use .object-{fit} with an <img> or <video> element that has a set width and height to control how its content fills that space.

Use .object-cover to fill the space, cropping the image if its proportions are different, and .object-contain to fit the whole image within the space, leaving empty space around it if needed. .object-fill stretches the image to fill the space, and .object-none shows the image at its original size, centered and cropped.

<img class="object-cover w-full" style="height: 120px;" src="..." alt="...">
<img class="object-contain w-full" style="height: 120px;" src="..." alt="...">
<img class="object-fill w-full" style="height: 120px;" src="..." alt="...">
<img class="object-none w-full" style="height: 120px;" src="..." alt="...">

Variants

By default, only responsive variants are generated for object fit utilities.

Responsive

To control how an image fits its container at a specific breakpoint, add a {screen}: prefix to any existing object fit utility.

For example, use .md:object-cover to apply the object-cover utility at only medium screen sizes and above.

Hover-state

To include hover-state variants like .hover:object-cover, add "object-fit" to the $hover-variants variable when recompiling your CSS:

$hover-variants: (
  // ...
  "object-fit",
);

Questions or feedback about this article? Let us know