The object-fit property sets how the content of a replaced element — usually an <img> or <video> — is resized to fit the element’s own box.
Give the media a width and height first. Then choose a keyword: stretch with fill, crop to fill with cover, or show the whole image with contain. Crop focus is controlled by object-position. It has no effect on <iframe>, <embed>, or <fencedframe>.
Baseline · Widely available.
Not deprecated and not experimental. Safe in current browsers since Safari 10. Internet Explorer has no support.
A cropped photo can hide details. Keep meaningful alt text so assistive tech still describes the image.
Compatibility
Browser Support
object-fit is a browser CSS property for replaced elements. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available since 2020
object-fit
Chrome 31+, Firefox 36+, Safari 10+, Edge 16+, Opera 19+. Internet Explorer has no native support.
97%Modern browser support
Google Chrome31+ · Desktop & Mobile
Full support
Mozilla Firefox36+ · Desktop & Mobile
Full support
Apple Safari10+ · macOS & iOS
Full support
Microsoft Edge16+ · Chromium & Legacy
Full support
Opera19+ · Modern versions
Full support
Samsung Internet3+ · Android
Full support
Internet ExplorerNo support
None
object-fitWidely supported
Bottom line: Safe for modern responsive layouts. For Internet Explorer, size the box and accept stretch, or use a background-image fallback. Pair with aspect-ratio for predictable media frames.
Remember
Key Takeaways
Role: scale replaced content inside its own width and height box.
Everyday picks:cover for cards and heroes; contain for logos and product shots.
Default:fill stretches. Prefer cover or contain for photos.
Companion:object-position steers the crop. Not inherited.
One line: size the media box, then let object-fit decide stretch, crop, or letterbox.
Frequently Asked Questions
It controls how replaced content such as an image or video is resized inside its own box. You pick fill, contain, cover, none, or scale-down.
fill. The content stretches to match both width and height, which can distort the aspect ratio.
cover fills the box and may crop edges. contain keeps the whole image visible and may leave empty space. Both keep the aspect ratio.
The element needs a defined width and height that differ from the media's natural size. Without a sized box, there is nothing to fit into.
No. Per the CSS Images specification and MDN, object-fit has no effect on iframe, embed, or fencedframe. Use it on img, video, and similar replaced elements.
It is Baseline and widely available: Chrome 31+, Firefox 36+, Safari 10+, Edge 16+, and Opera 19+. Internet Explorer has no support. It is a browser CSS property, not a Node.js feature.