Object Fit

Set how to resize the content of a replaced element.

Widely available

This feature is well established and works across many devices and browser versions.

Chrome
Edge
Firefox
Safari

Usage

Fill

Stretch the content to fill the entire container.

<div class="h-40 w-80">
<img class="of-f w-full h-full" src="/img/coast.jpg" />
</div>

Cover

Scale the content to cover the entire container.

<div class="h-40 w-80">
<img class="of-c w-full h-full" src="/img/coast.jpg" />
</div>

None

Display the content at its original size.

<div class="h-40 w-80">
<img class="of-none w-full h-full" src="/img/coast.jpg" />
</div>

Scale Down

Size the content as if none or contain was specified.

<div class="h-40 w-80">
<img class="of-sd w-full h-full" src="/img/coast.jpg" />
</div>

Responsiveness

Use breakpoint prefixes to target different screen sizes. Styles apply from the breakpoint & up.

Target viewport sizes with breakpoint prefixes.

sm:of-*
Small640px
md:of-*
Medium768px
lg:of-*
Large1024px
xxl:of-*
Extra Large1536px

Hover State

Apply styles conditionally on hover using the h: prefix.

Add the h: prefix to apply styles only when the user hovers over the element.

Syntax:h:of-*