Stop images from stretching. Control exactly how they fill their container.
Click any value card below to see how it affects the same image inside a fixed container. Then drag the sliders to resize the container and watch each value respond differently.




cover for card thumbnails, hero images, and avatars — it fills the space and looks great.
Use contain for logos, product images, and icons where showing the full image matters more than filling the box.
Avoid fill — it always distorts.
When object-fit: cover crops an image, it centers by default. object-position
lets you choose which part of the image stays visible. Click a position below to see it live.
Subject may be cropped out depending on image composition.
Face/subject stays in frame. Same image, better crop.
Click any position to see how the same image crops differently.
center
object-position: top
to keep faces in frame. For landscape photos in square containers, use object-position: center
(default) or a custom percentage like 50% 20% to keep the horizon visible.
The most common places developers use object-fit, and why it sometimes silently stops working.
object-fit: cover on a fixed width/height circle keeps faces centered without distortion.
Cards with fixed height thumbnail areas need cover — images never stretch regardless of their original dimensions.
object-fit works on <video> too — perfect for fullscreen background videos that must fill the container without black bars.
Use contain for logos and product shots — the full image is always visible with no cropping, letterboxed inside the container.
object-fit only works when the <img> has a defined width and height. Without them, the image sizes to its natural dimensions and there's nothing to "fit" into.
object-fit only works on replaced elements — elements where the content is external: <img>, <video>, <iframe>, <canvas>. It has no effect on <div> or any regular element.
Both object-fit: cover and background-size: cover do similar things — but for different elements. object-fit is for <img> and <video> tags. background-size is for CSS background images on any element.
<img> have explicit width and height? (2) Is it on an <img> or <video> — not a <div>? (3) Meant to use background-size instead?