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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1584516150909-c43483ee7932?auto=format&fit=crop&w=1600&h=700&q=70" alt="Five things we learned this year" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1758691461990-03b49d969495?auto=format&fit=crop&w=1200&h=800&q=70" alt="What our patients asked us most" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1758691462126-2ee47c8bf9e7?auto=format&fit=crop&w=800&h=800&q=70" alt="Simple habits for a healthier back" 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="https://images.unsplash.com/photo-1758691463331-2ac00e6f676f?auto=format&fit=crop&w=1200&h=800&q=70" alt="Chloe Haddad" width="72" height="72" class="rounded-full object-cover border">
<div>
<div class="font-semibold">
Chloe Haddad
</div>
<div class="small text-muted">
HR Partner
</div>
</div>
</div>5Hero banner crop
A fixed height banner with object-fit-cover keeps its height on every screen.
<img src="https://images.unsplash.com/photo-1584516150909-c43483ee7932?auto=format&fit=crop&w=1200&h=800&q=70" alt="Your health, our priority" 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="https://images.unsplash.com/photo-1581056771107-24ca5f033842?auto=format&fit=crop&w=800&h=800&q=70" 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="https://images.unsplash.com/photo-1581056771107-24ca5f033842?auto=format&fit=crop&w=800&h=800&q=70" 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="https://images.unsplash.com/photo-1758691461990-03b49d969495?auto=format&fit=crop&w=1600&h=700&q=70" alt="Care for the whole family" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1200&h=800&q=70" 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="https://images.unsplash.com/photo-1758691463331-2ac00e6f676f?auto=format&fit=crop&w=800&h=800&q=70" alt="Gallery small 1" class="w-full rounded-lg object-cover" style="height:96px"> <img src="https://images.unsplash.com/photo-1758691462858-f1286e5daf40?auto=format&fit=crop&w=1600&h=700&q=70" 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.
Book a doctor in minutes
See a specialist this week
Your health, our priority
<ul class="list-unstyled mb-0 grid gap-2">
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">Book a doctor in minutes</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1581056771107-24ca5f033842?auto=format&fit=crop&w=1200&h=800&q=70" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">See a specialist this week</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1758691462123-8a17ae95d203?auto=format&fit=crop&w=1600&h=700&q=70" alt="" width="52" height="52" class="rounded-md object-cover shrink-0"><span class="small">Your health, our priority</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-4.svg" alt="Blood test" class="w-full object-scale-down bg-surface-3 rounded-lg" style="height:180px">
<div class="p-2">
<div class="font-medium">
Blood test
</div>
<div class="small">
$74.48
</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="https://images.unsplash.com/photo-1631217868264-e5b90bb7e133?auto=format&fit=crop&w=800&h=800&q=70" alt="Understanding your blood test results" 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="https://images.unsplash.com/photo-1631217871099-88310a909a32?auto=format&fit=crop&w=1600&h=700&q=70" alt="Cover 1" class="object-cover rounded-lg">
</div>
</div>
<div class="col-4">
<div class="ratio ratio-1x1">
<img src="https://images.unsplash.com/photo-1758691462126-2ee47c8bf9e7?auto=format&fit=crop&w=1200&h=800&q=70" alt="Cover 2" class="object-cover rounded-lg">
</div>
</div>
<div class="col-4">
<div class="ratio ratio-1x1">
<img src="https://images.unsplash.com/photo-1631217868264-e5b90bb7e133?auto=format&fit=crop&w=1600&h=700&q=70" 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="https://images.unsplash.com/photo-1758691461990-03b49d969495?auto=format&fit=crop&w=1600&h=700&q=70" alt="Lea Varga" width="110" height="150" class="rounded-lg object-cover">
<div>
<div class="font-semibold">
Lea Varga
</div>
<div class="small text-muted">
QA Engineer
</div>
</div>
</div>14Background-like image
An absolutely positioned image with object-fit-cover behaves like a cover background.
Healthcare that fits your life
Our specialists take time to listen and explain every step of your treatment.
<div class="relative rounded-xl overflow-hidden text-white p-6" style="min-height:170px">
<img src="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1200&h=800&q=70" 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">Healthcare that fits your life</h3>
<p class="small mb-0">Our specialists take time to listen and explain every step of your treatment.</p>
</div>
</div>15None keeps original pixels
object-fit-none shows the image at its natural size, cropped to the frame centre.
<img src="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1600&h=700&q=70" alt="The small habits that make a big difference" 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="https://images.unsplash.com/photo-1631217868264-e5b90bb7e133?auto=format&fit=crop&w=1200&h=800&q=70" alt="Zoe" width="80" height="80" class="rounded-full object-cover block mb-1">Zoe
</div>
<div>
<img src="https://images.unsplash.com/photo-1631217873436-b0fa88e71f0a?auto=format&fit=crop&w=800&h=800&q=70" alt="Tariq" width="80" height="80" class="rounded-full object-cover block mb-1">Tariq
</div>
<div>
<img src="https://images.unsplash.com/photo-1758691462878-6edc3d3da1be?auto=format&fit=crop&w=1600&h=700&q=70" alt="Ruby" width="80" height="80" class="rounded-full object-cover block mb-1">Ruby
</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="https://images.unsplash.com/photo-1758691462858-f1286e5daf40?auto=format&fit=crop&w=800&h=800&q=70" alt="What to expect at your first dental visit" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
What to expect at your first dental visit
</div>
</div>
</div>
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="https://images.unsplash.com/photo-1631217873436-b0fa88e71f0a?auto=format&fit=crop&w=1600&h=700&q=70" alt="When to choose a video consultation" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
When to choose a video consultation
</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="https://images.unsplash.com/photo-1584516150909-c43483ee7932?auto=format&fit=crop&w=1200&h=800&q=70" alt="How often should you have a health check-up?" 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="https://images.unsplash.com/photo-1606318313647-137d1f3b4d3c?auto=format&fit=crop&w=1200&h=800&q=70" 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-ink" 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="https://images.unsplash.com/photo-1631217871099-88310a909a32?auto=format&fit=crop&w=1200&h=800&q=70" 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="https://images.unsplash.com/photo-1758691463331-2ac00e6f676f?auto=format&fit=crop&w=1200&h=800&q=70" 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>