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-1682264933304-1943bfa8df38?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-1682264933304-1943bfa8df38?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-1682264933304-1943bfa8df38?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-1682264933304-1943bfa8df38?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-1682264933304-1943bfa8df38?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-1625862692743-3f57873bb37c?auto=format&fit=crop&w=1600&h=700&q=70" alt="Three pasta shapes to make at home" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1565895405140-6b9830a88c19?auto=format&fit=crop&w=1200&h=800&q=70" alt="Planning the perfect birthday dinner" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1538333581680-29dd4752ddf2?auto=format&fit=crop&w=800&h=800&q=70" alt="Our chocolate tart, step by step" 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-1682264933304-1943bfa8df38?auto=format&fit=crop&w=1200&h=800&q=70" alt="Arjun Hughes" width="72" height="72" class="rounded-full object-cover border">
<div>
<div class="font-semibold">
Arjun Hughes
</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-1570560258879-af7f8e1447ac?auto=format&fit=crop&w=1200&h=800&q=70" alt="Cooked with care, served with a smile" 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-1559339352-11d035aa65de?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-1559339352-11d035aa65de?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-1712746784068-703c0c915611?auto=format&fit=crop&w=1600&h=700&q=70" alt="Good food brings people together" 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-1551632436-cbf8dd35adfa?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-1712746784068-703c0c915611?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-1541963020-4f9732b3ee29?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.
Come hungry, leave happy
Simple dishes, honest ingredients
A table for every occasion
<ul class="list-unstyled mb-0 grid gap-2">
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1551632436-cbf8dd35adfa?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">Come hungry, leave happy</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1559339352-11d035aa65de?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">Simple dishes, honest ingredients</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1494346480775-936a9f0d0877?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">A table for every occasion</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="Wood-fired pizza" class="w-full object-scale-down bg-surface-3 rounded-lg" style="height:180px">
<div class="p-2">
<div class="font-medium">
Wood-fired pizza
</div>
<div class="small">
$89.08
</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-1565895405140-6b9830a88c19?auto=format&fit=crop&w=800&h=800&q=70" alt="How we make our sourdough every morning" 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-1570560258879-af7f8e1447ac?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-1538333581680-29dd4752ddf2?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-1517248135467-4c7edcad34c4?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-1565895405140-6b9830a88c19?auto=format&fit=crop&w=1600&h=700&q=70" alt="Noah Mensah" width="110" height="150" class="rounded-lg object-cover">
<div>
<div class="font-semibold">
Noah Mensah
</div>
<div class="small text-muted">
Sales Executive
</div>
</div>
</div>14Background-like image
An absolutely positioned image with object-fit-cover behaves like a cover background.
Fresh flavours, made every day
We measure success by how many guests come back and tell their friends.
<div class="relative rounded-xl overflow-hidden text-white p-6" style="min-height:170px">
<img src="https://images.unsplash.com/photo-1570560258879-af7f8e1447ac?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">Fresh flavours, made every day</h3>
<p class="small mb-0">We measure success by how many guests come back and tell their friends.</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-1551632436-cbf8dd35adfa?auto=format&fit=crop&w=1600&h=700&q=70" alt="Our chef's guide to seasonal autumn produce" 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-1517248135467-4c7edcad34c4?auto=format&fit=crop&w=1200&h=800&q=70" alt="Mia" width="80" height="80" class="rounded-full object-cover block mb-1">Mia
</div>
<div>
<img src="https://images.unsplash.com/photo-1682264933304-1943bfa8df38?auto=format&fit=crop&w=800&h=800&q=70" alt="Isla" width="80" height="80" class="rounded-full object-cover block mb-1">Isla
</div>
<div>
<img src="https://images.unsplash.com/photo-1579631542761-d7c4e913f8d4?auto=format&fit=crop&w=1600&h=700&q=70" alt="Arjun" width="80" height="80" class="rounded-full object-cover block mb-1">Arjun
</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-1541963020-4f9732b3ee29?auto=format&fit=crop&w=800&h=800&q=70" alt="What our guests asked us most" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
What our guests asked us most
</div>
</div>
</div>
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="https://images.unsplash.com/photo-1682264933304-1943bfa8df38?auto=format&fit=crop&w=1600&h=700&q=70" alt="Vegan dishes worth crossing town for" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
Vegan dishes worth crossing town for
</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-1570560258879-af7f8e1447ac?auto=format&fit=crop&w=1200&h=800&q=70" alt="The small habits that make a big difference" 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-1570560258879-af7f8e1447ac?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-1570560258879-af7f8e1447ac?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-1712746784068-703c0c915611?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>