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="https://images.unsplash.com/photo-1690264351371-b75a9a9bdbdd?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-1690264351371-b75a9a9bdbdd?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-1690264351371-b75a9a9bdbdd?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-1690264351371-b75a9a9bdbdd?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-1690264351371-b75a9a9bdbdd?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-1554902843-260acd0993f8?auto=format&fit=crop&w=1600&h=700&q=70" alt="Planning a product launch in six weeks" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1758691737124-05c5bffe46f0?auto=format&fit=crop&w=1200&h=800&q=70" alt="What we learned shipping 200 releases" class="w-full rounded-lg object-cover" style="height:110px">
</div>
<div class="col-4">
<img src="https://images.unsplash.com/photo-1690264421892-46e3af5c3455?auto=format&fit=crop&w=800&h=800&q=70" alt="How we cut our release cycle in half" 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-1702301266409-ed1bfe210971?auto=format&fit=crop&w=1200&h=800&q=70" alt="Owen Morgan" width="72" height="72" class="rounded-full object-cover border">
<div>
<div class="font-semibold">
Owen Morgan
</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-1702301266409-ed1bfe210971?auto=format&fit=crop&w=1200&h=800&q=70" alt="Ship faster with less busywork" 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-1742440711276-679934f5b988?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-1742440711276-679934f5b988?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-1690378820474-b468b8ee64d3?auto=format&fit=crop&w=1600&h=700&q=70" alt="One platform for every workflow" 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-1690264350953-79ef8acbd562?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-1742440711276-679934f5b988?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-1522202176988-66273c2fd55f?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.
Fewer meetings, more finished work
Plan, build and launch in one place
Know what is happening, without asking
<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">Fewer meetings, more finished work</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1702301266409-ed1bfe210971?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">Plan, build and launch in one place</span></li>
<li class="flex gap-2 items-center"><img src="https://images.unsplash.com/photo-1690264351371-b75a9a9bdbdd?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">Know what is happening, without asking</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="Enterprise suite" class="w-full object-scale-down bg-surface-3 rounded-lg" style="height:180px">
<div class="p-2">
<div class="font-medium">
Enterprise suite
</div>
<div class="small">
$14.05
</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-1742440711276-679934f5b988?auto=format&fit=crop&w=800&h=800&q=70" alt="A beginner's guide to getting started" 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-1690264459911-6d68c747d8a7?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-1690264421892-46e3af5c3455?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-1690378820474-b468b8ee64d3?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-1531545514256-b1400bc00f31?auto=format&fit=crop&w=1600&h=700&q=70" alt="Leo Delgado" width="110" height="150" class="rounded-lg object-cover">
<div>
<div class="font-semibold">
Leo Delgado
</div>
<div class="small text-muted">
Customer Success
</div>
</div>
</div>14Background-like image
An absolutely positioned image with object-fit-cover behaves like a cover background.
One platform for every workflow
Every update lands in one place, so nothing gets lost in email threads.
<div class="relative rounded-xl overflow-hidden text-white p-6" style="min-height:170px">
<img src="https://images.unsplash.com/photo-1531545514256-b1400bc00f31?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">One platform for every workflow</h3>
<p class="small mb-0">Every update lands in one place, so nothing gets lost in email threads.</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-1702301266409-ed1bfe210971?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="../assets/img/photo-1.svg" alt="Ava" width="80" height="80" class="rounded-full object-cover block mb-1">Ava
</div>
<div>
<img src="https://images.unsplash.com/photo-1531545514256-b1400bc00f31?auto=format&fit=crop&w=800&h=800&q=70" alt="Freya" width="80" height="80" class="rounded-full object-cover block mb-1">Freya
</div>
<div>
<img src="https://images.unsplash.com/photo-1742440710136-1976b1cad864?auto=format&fit=crop&w=1600&h=700&q=70" alt="Zoe" width="80" height="80" class="rounded-full object-cover block mb-1">Zoe
</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-1522202176988-66273c2fd55f?auto=format&fit=crop&w=800&h=800&q=70" alt="How to choose the right plan" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
How to choose the right plan
</div>
</div>
</div>
<div class="col-6">
<div class="border rounded-xl overflow-hidden">
<img src="https://images.unsplash.com/photo-1531545514256-b1400bc00f31?auto=format&fit=crop&w=1600&h=700&q=70" alt="What we learned shipping 200 releases" class="w-full object-cover" style="height:110px">
<div class="p-2 small font-medium">
What we learned shipping 200 releases
</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-1690264459911-6d68c747d8a7?auto=format&fit=crop&w=1200&h=800&q=70" alt="Looking back at a busy season" 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-1554902843-260acd0993f8?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-1690264459911-6d68c747d8a7?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-1742440711276-679934f5b988?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>