Object fit

Use the object fit utilities to modify how the content of a replaced element, such as an <img> or <video>, should be resized to fit its container.

How it works

Change the value of the object-fit property with our responsive object-fit utility classes. This property tells the content to fill the parent container in a variety of ways, such as preserving the aspect ratio or stretching to take up as much space as possible.

Classes for the value of object-fit are named using the format .object-fit-{value}. Choose from the following values:

  • contain
  • cover
  • fill
  • scale (for scale-down)
  • none

Examples

Add the object-fit-{value} class to the replaced element:

Placeholder: Object fit containPlaceholder: Object fit coverPlaceholder: Object fit fillPlaceholder: Object fit scale downPlaceholder: Object fit none
html

Responsive

Responsive variations also exist for each object-fit value using the format .object-fit-{breakpoint}-{value}, for the following breakpoint abbreviations: sm, md, lg, xl, and xxl. Classes can be combined for various effects as you need.

Placeholder: Contain on smPlaceholder: Contain on mdPlaceholder: Contain on lgPlaceholder: Contain on xlPlaceholder: Contain on xxl
html

Video

The .object-fit-{value} and responsive .object-fit-{breakpoint}-{value} utilities also work on <video> elements.

html

CSS

Sass utilities API

Object fit utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.