Media

Aspect-ratio and object-fit/object-position utilities for images, video, and iframes - keep media proportioned without wrapper hacks.

Aspect ratio

.aspect-* (aliased as .as-*) sets the aspect-ratio property directly on the element.

Preview

1 / 1
16 / 9
<div class="aspect-square" style="width:100px;"></div>
<iframe class="aspect-video w-full" src="..."></iframe>
Classaspect-ratio
.aspect-auto / .as-autoauto
.aspect-square / .as-square1 / 1
.aspect-video / .as-video16 / 9

Object fit

.object-{value} controls how an image or video is resized to fit its box - identical vocabulary to the CSS object-fit property.

<img class="object-cover aspect-video w-full" src="banner.jpg" alt="">
Classobject-fit
.object-covercover
.object-containcontain
.object-fillfill
.object-scale-downscale-down
.object-nonenone

Object position

Combine with .object-{side} to control which part of the media stays visible when it's cropped.

<img class="object-cover object-top aspect-square" src="portrait.jpg" alt="">
Classobject-position
.object-centercenter
.object-top / .object-bottomtop / bottom
.object-left / .object-rightleft / right
.object-top-lefttop left
.object-top-righttop right
.object-bottom-leftbottom left
.object-bottom-rightbottom right
Pair with sizing. object-fit only has an effect once the element has an explicit box - combine with .aspect-*, .w-*/.h-*, from Sizing.