Object Fit
Object fit utilities decide how an image or video fills its box: object-fit-contain shows all of it, object-fit-cover fills the box and crops, object-fit-fill stretches, object-fit-scale only shrinks and object-fit-none keeps the natural size. Responsive variants like object-fit-md-cover switch per breakpoint.
1All object-fit values
contain, cover, fill, scale and none on the same wide image in square frames.
object-fit-containobject-fit-coverobject-fit-fillobject-fit-scaleobject-fit-none<div class="row g-3 text-center small">
<div class="col-6 col-md">
<img src="../assets/img/wide-8.svg" alt="contain" width="120" height="120" class="bg-surface-3 border rounded-lg block object-contain mx-auto"><code>object-fit-contain</code>
</div>
<div class="col-6 col-md">
<img src="../assets/img/wide-8.svg" alt="cover" width="120" height="120" class="bg-surface-3 border rounded-lg block object-cover mx-auto"><code>object-fit-cover</code>
</div>
<div class="col-6 col-md">
<img src="../assets/img/wide-8.svg" alt="fill" width="120" height="120" class="bg-surface-3 border rounded-lg block object-fill mx-auto"><code>object-fit-fill</code>
</div>
<div class="col-6 col-md">
<img src="../assets/img/wide-8.svg" alt="scale" width="120" height="120" class="bg-surface-3 border rounded-lg block object-scale-down mx-auto"><code>object-fit-scale</code>
</div>
<div class="col-6 col-md">
<img src="../assets/img/wide-8.svg" alt="none" width="120" height="120" class="bg-surface-3 border rounded-lg block object-none mx-auto"><code>object-fit-none</code>
</div>
</div>2Uniform product grid
object-fit-cover makes images of any shape fill equal square tiles.
<div class="row g-2">
<div class="col-4">
<img src="../assets/img/wide-1.svg" alt="6 lessons from our plan" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="../assets/img/photo-2.svg" alt="4 lessons from our workflow" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="../assets/img/square-3.svg" alt="Launch notes for attendees" class="w-full rounded-lg object-cover" style="height:110px">
</div>
</div>3Logos with contain
object-fit-contain shows the whole logo inside a fixed box without cropping.
<div class="flex flex-wrap gap-2">
<img src="../assets/img/logo-5.svg" alt="Partner logo" width="130" height="70" class="object-contain border rounded-lg p-2 bg-page"> <img src="../assets/img/logo-6.svg" alt="Partner logo" width="130" height="70" class="object-contain border rounded-lg p-2 bg-page"> <img src="../assets/img/logo-7.svg" alt="Partner logo" width="130" height="70" class="object-contain border rounded-lg p-2 bg-page">
</div>4Round avatar from a wide photo
object-fit-cover with rounded-circle crops a non-square image into a circle.
<div class="flex items-center gap-4">
<img src="../assets/img/photo-4.svg" alt="Liam Ashford" width="72" height="72" class="rounded-full object-cover border">
<div>
<div class="font-semibold">
Liam Ashford
</div>
<div class="small text-muted">
Data Analyst
</div>
</div>
</div>5Hero banner crop
A fixed height banner with object-fit-cover keeps its height on every screen.
<img src="../assets/img/photo-6.svg" alt="Where great ideas meet" class="w-full rounded-xl object-cover" style="height:160px">6Fill stretches the image
object-fit-fill ignores the aspect ratio, which distorts the picture - compare with cover.
<div class="flex flex-wrap gap-4 small">
<figure class="mb-0">
<img src="../assets/img/square-5.svg" alt="Stretched" width="200" height="90" class="object-fill rounded-lg border block">
<figcaption class="mt-1">fill</figcaption>
</figure>
<figure class="mb-0">
<img src="../assets/img/square-5.svg" alt="Cropped" width="200" height="90" class="object-cover rounded-lg border block">
<figcaption class="mt-1">cover</figcaption>
</figure>
</div>7Responsive object fit
object-fit-contain object-fit-md-cover shows the full image on phones and crops it from md.
<img src="../assets/img/wide-6.svg" alt="Learn, connect and get inspired" class="w-full rounded-xl border bg-surface-3 object-contain md:object-cover" style="height:180px">8Gallery with mixed shapes
A two row mosaic: each cell is a fixed height and the images cover it.
<div class="row g-2">
<div class="col-8">
<img src="../assets/img/photo-5.svg" alt="Gallery large" class="w-full rounded-lg object-cover" style="height:200px">
</div>
<div class="col-4 flex flex-col gap-2">
<img src="../assets/img/square-6.svg" alt="Gallery small 1" class="w-full rounded-lg object-cover" style="height:96px"> <img src="../assets/img/wide-7.svg" alt="Gallery small 2" class="w-full rounded-lg object-cover" style="height:96px">
</div>
</div>9Thumbnail list
Small square thumbnails with object-fit-cover in a list of articles.
Experiences people talk about
Learn, connect and get inspired
Experiences people talk about
<ul class="list-unstyled mb-0 grid gap-2">
<li class="flex gap-2 items-center"><img src="../assets/img/wide-2.svg" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">Experiences people talk about</span></li>
<li class="flex gap-2 items-center"><img src="../assets/img/photo-3.svg" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">Learn, connect and get inspired</span></li>
<li class="flex gap-2 items-center"><img src="../assets/img/wide-4.svg" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">Experiences people talk about</span></li>
</ul>10Product image with scale
object-fit-scale never enlarges a small image, it only shrinks large ones.
<div class="border rounded-xl p-2 bg-page" style="max-width:16rem">
<img src="../assets/img/product-1.svg" alt="Group bundle" class="w-full object-scale-down bg-surface-3 rounded-lg" style="height:180px">
<div class="p-2">
<div class="font-medium">
Group bundle
</div>
<div class="small">
$56.86
</div>
</div>
</div>11Cover inside a ratio box
ratio ratio-16x9 sets the frame; object-fit-cover fills it with the image.
<div class="ratio ratio-16x9 rounded-xl overflow-hidden" style="max-width:26rem">
<img src="../assets/img/square-11.svg" alt="Inside the elegant plan" class="object-cover">
</div>12Square ratio cards
ratio-1x1 with object-fit-cover gives every card a square cover.
<div class="row g-2">
<div class="col-4">
<div class="ratio ratio-1x1">
<img src="../assets/img/wide-8.svg" alt="Cover 1" class="object-cover rounded-lg">
</div>
</div>
<div class="col-4">
<div class="ratio ratio-1x1">
<img src="../assets/img/photo-9.svg" alt="Cover 2" class="object-cover rounded-lg">
</div>
</div>
<div class="col-4">
<div class="ratio ratio-1x1">
<img src="../assets/img/wide-10.svg" alt="Cover 3" class="object-cover rounded-lg">
</div>
</div>
</div>13Portrait crop
A tall fixed width and height frame with object-fit-cover turns a landscape photo into a portrait.
<div class="flex gap-4 items-end">
<img src="../assets/img/wide-10.svg" alt="Samir Patel" width="110" height="150" class="rounded-lg object-cover">
<div>
<div class="font-semibold">
Samir Patel
</div>
<div class="small text-muted">
Data Analyst
</div>
</div>
</div>14Background-like image
An absolutely positioned image with object-fit-cover behaves like a cover background.
Experiences people talk about
This modern dashboard gives complex tasks into simple steps on any device.
<div class="relative rounded-xl overflow-hidden text-white p-6" style="min-height:170px">
<img src="../assets/img/photo-10.svg" alt="" class="absolute top-0 start-0 w-full h-full object-cover">
<div class="absolute top-0 start-0 w-full h-full bg-dark/50">
</div>
<div class="relative">
<h3 class="h5 font-bold">Experiences people talk about</h3>
<p class="small mb-0">This modern dashboard gives complex tasks into simple steps on any device.</p>
</div>
</div>15None keeps original pixels
object-fit-none shows the image at its natural size, cropped to the frame centre.
<img src="../assets/img/wide-6.svg" alt="A guide to sponsorship" class="w-full object-none rounded-xl border" style="height:140px">16Team grid
Team photos in equal circles, whatever the source image size.
<div class="flex flex-wrap gap-4 text-center small">
<div>
<img src="../assets/img/photo-1.svg" alt="Diego" width="80" height="80" class="rounded-full object-cover block mb-1">Diego
</div>
<div>
<img src="../assets/img/square-2.svg" alt="Luna" width="80" height="80" class="rounded-full object-cover block mb-1">Luna
</div>
<div>
<img src="../assets/img/wide-3.svg" alt="Amara" width="80" height="80" class="rounded-full object-cover block mb-1">Amara
</div>
</div>17Card top image
A card with a fixed height cover image keeps all cards in a row aligned.
<div class="row g-3">
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="../assets/img/square-4.svg" alt="A guide to sponsorship" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
A guide to sponsorship
</div>
</div>
</div>
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="../assets/img/wide-5.svg" alt="A guide to networking app" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
A guide to networking app
</div>
</div>
</div>
</div>18Contain on a dark stage
object-fit-contain on bg-dark: a lightbox style viewer that never crops.
<div class="bg-dark rounded-xl p-2">
<img src="../assets/img/photo-2.svg" alt="The focused dashboard checklist" class="w-full object-contain" style="height:200px">
</div>19Video poster tile
A cover image in a 21x9 ratio with a play icon.
<div class="ratio ratio-21x9 rounded-xl overflow-hidden" style="max-width:28rem">
<img src="../assets/img/photo-3.svg" alt="Video poster" class="object-cover">
<div class="flex items-center justify-center">
<span class="bg-page rounded-full shadow-md inline-flex items-center justify-center text-xl text-primary" style="width:56px;height:56px"><i class="bi bi-play-fill" aria-hidden="true"></i></span>
</div>
</div>20Compare before and after
Two cover images side by side with labels.
<div class="row g-2 small">
<div class="col-6 relative">
<img src="../assets/img/photo-11.svg" alt="Before" class="w-full rounded-lg object-cover" style="height:130px"><span class="absolute top-0 start-0 m-2 badge text-bg-dark">Before</span>
</div>
<div class="col-6 relative">
<img src="../assets/img/photo-12.svg" alt="After" class="w-full rounded-lg object-cover" style="height:130px"><span class="absolute top-0 start-0 m-2 badge text-bg-primary">After</span>
</div>
</div>