CSS object-fit Property Explained
What the CSS object-fit property does, with an example.
Published November 5, 2026
object-fit controls how an image or video fills its box: fill (stretch), contain (fit inside), cover (fill and crop), none or scale-down.
How it works
cover is the usual choice for thumbnails and avatars: the media fills the box and is cropped to preserve aspect ratio. contain shows everything with possible empty bars.
Use object-position to choose which part stays visible.
Values and effects
object-fit: fill; → stretches (default)
object-fit: contain; → whole image visible
object-fit: cover; → fills and crops
object-fit: scale-down; → smaller of none/contain
Practical examples
Square thumbnail
.thumb { width: 200px; height: 200px; object-fit: cover; }Keep focal point
.hero { object-fit: cover; object-position: top center; }Logo
.logo { width: 120px; height: 60px; object-fit: contain; }Common mistakes
- Forgetting to set width and height so nothing is cropped.
- Using fill and distorting images.
- Not choosing object-position for faces.
Key takeaways
- object-fit in one line: object-fit controls how an image or video fills its box: fill (stretch), contain (fit inside), cover (fill and crop), none or scale-down.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
cover vs contain?
cover fills the box and crops; contain fits everything with spare space.
Is object-fit supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.