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-1521335629791-ce4aec67dd15?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-1521335629791-ce4aec67dd15?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-1521335629791-ce4aec67dd15?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-1521335629791-ce4aec67dd15?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-1521335629791-ce4aec67dd15?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-1567958451986-2de427a4a0be?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-1441984904996-e0b6ba687e04?auto=format&fit=crop&w=1200&h=800&q=70" alt="Inside our new autumn collection" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1443884590026-2e4d21aee71c?auto=format&fit=crop&w=800&h=800&q=70" alt="Styling one piece three different ways" 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-1601647998829-ee316a565aea?auto=format&fit=crop&w=1200&h=800&q=70" alt="Diego Patel" width="72" height="72" class="rounded-full object-cover border">
<div>
<div class="font-semibold">
Diego Patel
</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="https://images.unsplash.com/photo-1567401893414-76b7b1e5a7a5?auto=format&fit=crop&w=1200&h=800&q=70" alt="Good things, made to be used" 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-1567401893414-76b7b1e5a7a5?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-1567401893414-76b7b1e5a7a5?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-1573612664822-d7d347da7b80?auto=format&fit=crop&w=1600&h=700&q=70" alt="Shop the collection everyone talks about" 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-1718985342149-7178154e0aee?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-1580418835996-7783da1c3c6c?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-1598305762558-328f599df683?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.
Designed to last, priced to love
Shop the collection everyone talks about
Good things, made to be used
<ul class="list-unstyled mb-0 grid gap-2">
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1718985342149-7178154e0aee?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">Designed to last, priced to love</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1567401893414-76b7b1e5a7a5?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">Shop the collection everyone talks about</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1521335629791-ce4aec67dd15?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">Good things, made to be used</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="Leather wallet" class="w-full object-scale-down bg-surface-3 rounded-lg" style="height:180px">
<div class="p-2">
<div class="font-medium">
Leather wallet
</div>
<div class="small">
$17.98
</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-1441984904996-e0b6ba687e04?auto=format&fit=crop&w=800&h=800&q=70" alt="How to choose the right product" 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-1601647998829-ee316a565aea?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-1443884590026-2e4d21aee71c?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-1441986300917-64674bd600d8?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-1718985342149-7178154e0aee?auto=format&fit=crop&w=1600&h=700&q=70" alt="Ravi Morgan" width="110" height="150" class="rounded-lg object-cover">
<div>
<div class="font-semibold">
Ravi Morgan
</div>
<div class="small text-muted">
Product Designer
</div>
</div>
</div>14Background-like image
An absolutely positioned image with object-fit-cover behaves like a cover background.
New season, new favourites
We keep things simple, so you can focus on what matters to you.
<div class="relative rounded-xl overflow-hidden text-white p-6" style="min-height:170px">
<img src="https://images.unsplash.com/photo-1567401893414-76b7b1e5a7a5?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">New season, new favourites</h3>
<p class="small mb-0">We keep things simple, so you can focus on what matters to you.</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-1580418835996-7783da1c3c6c?auto=format&fit=crop&w=1600&h=700&q=70" alt="What to pack for a rainy weekend outdoors" 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-1441986300917-64674bd600d8?auto=format&fit=crop&w=1200&h=800&q=70" alt="Nadia" width="80" height="80" class="rounded-full object-cover block mb-1">Nadia
</div>
<div>
<img src="https://images.unsplash.com/photo-1573612664822-d7d347da7b80?auto=format&fit=crop&w=800&h=800&q=70" alt="Ella" width="80" height="80" class="rounded-full object-cover block mb-1">Ella
</div>
<div>
<img src="https://images.unsplash.com/photo-1630905119003-329447458f85?auto=format&fit=crop&w=1600&h=700&q=70" alt="Priya" width="80" height="80" class="rounded-full object-cover block mb-1">Priya
</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-1598305762558-328f599df683?auto=format&fit=crop&w=800&h=800&q=70" alt="Our guide to gifts under $50" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
Our guide to gifts under $50
</div>
</div>
</div>
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="https://images.unsplash.com/photo-1573612664822-d7d347da7b80?auto=format&fit=crop&w=1600&h=700&q=70" alt="A three-step skincare routine that works" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
A three-step skincare routine that works
</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-1443884590026-2e4d21aee71c?auto=format&fit=crop&w=1200&h=800&q=70" alt="What to pack for a rainy weekend outdoors" 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-1573612664822-d7d347da7b80?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-1601647998829-ee316a565aea?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-1580418835996-7783da1c3c6c?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>