files/en-us/web/css/reference/properties/object-fit/index.md
The object-fit CSS property sets how the content of a {{ glossary("replaced elements", "replaced element")}}, such as an {{HTMLElement("img")}} or {{HTMLElement("video")}}, should be resized to fit its container.
[!NOTE] The
object-fitproperty has no effect on {{HTMLElement("iframe")}}, {{HTMLElement("embed")}}, and {{HTMLElement("fencedframe")}} elements.
You can alter the alignment of the replaced element's content object within the element's box using the {{cssxref("object-position")}} property.
{{InteractiveExample("CSS Demo: object-fit")}}
object-fit: fill;
object-fit: contain;
object-fit: cover;
object-fit: none;
object-fit: scale-down;
<section id="default-example">
</section>
#example-element {
height: 100%;
width: 100%;
border: 2px dotted #888888;
}
object-fit: contain;
object-fit: cover;
object-fit: fill;
object-fit: none;
object-fit: scale-down;
/* Global values */
object-fit: inherit;
object-fit: initial;
object-fit: revert;
object-fit: revert-layer;
object-fit: unset;
The object-fit property is specified as a single keyword chosen from the list of values below.
contain
cover
fill
none
scale-down
none or contain were specified, whichever would result in a smaller concrete object size.{{cssinfo}}
{{csssyntax}}
<section>
<h2>object-fit: fill</h2>
<h2>object-fit: contain</h2>
<h2>object-fit: cover</h2>
<h2>object-fit: none</h2>
<h2>object-fit: scale-down</h2>
</section>
h2 {
font-family: "Courier New", monospace;
font-size: 1em;
margin: 1em 0 0.3em;
}
img {
width: 150px;
height: 100px;
border: 1px solid black;
margin: 10px 0;
}
.narrow {
width: 100px;
height: 150px;
}
.fill {
object-fit: fill;
}
.contain {
object-fit: contain;
}
.cover {
object-fit: cover;
}
.none {
object-fit: none;
}
.scale-down {
object-fit: scale-down;
}
{{ EmbedLiveSample('Setting_object-fit_for_an_image', 500, 1100) }}
{{Specifications}}
{{Compat}}