CKTIS / CSS
object-fit — fitting content inside an element
object-fit controls how a replaced element’s content fits its content box. It can preserve proportions, crop an image, or stretch it without changing the dimensions of the element’s box.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
object-fit: fill | none | [contain | cover] || scale-down;object-fit controls how a replaced element’s content, such as an img image, fits its content box. It does not establish that box’s dimensions: the example uses width and height for that. Its initial value is fill; it is not inherited and has discrete animation.
fill fills the box and can distort proportions. contain preserves proportions and fits all content inside, potentially leaving empty bands. cover preserves proportions and covers the whole box, cropping content when necessary. none does not resize content to fit: it uses the default sizing algorithm, usually yielding natural dimensions. scale-down chooses the smaller result of none and contain.
Empty areas show the element’s background, and content extending beyond the box is clipped. object-position controls placement. This fits element content, not a background image controlled by background-size.
The Level 4 grammar also allows combining scale-down with contain or cover; standalone scale-down means contain scale-down. The cover scale-down variant chooses the smaller result of none and cover, so it can leave empty space. Specification inclusion does not establish browser support; combinations require separate verification.
Examples
<!doctype html>
<meta charset="utf-8">
<title>object-fit: contain</title>
<style>
img {
display: block;
width: 120px;
height: 120px;
object-fit: contain;
object-position: center;
background: #ddd;
}
</style>
<img alt="Red rectangle" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='100' viewBox='0 0 200 100'%3E%3Cpath fill='red' d='M0 0H200V100H0Z'/%3E%3C/svg%3E">Result
A 120 × 120 CSS-pixel image box containing a centered 120 × 60 red rectangle, with 30 CSS-pixel gray bands above and below.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.