Browse documentation
Reference / Layout
Object fit
Control how a replaced element such as an image fills a frame whose proportions differ from the original.
Working example
Contain preserves the whole image and may leave unused space. Cover fills the frame and crops the excess.
<figure class="flex flex-wrap gap-3">
<img class="h-20 w-20 border object-contain" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='80' viewBox='0 0 160 80'%3E%3Crect width='160' height='80' fill='%23ddd'/%3E%3Ccircle cx='32' cy='40' r='25'/%3E%3Crect x='100' y='15' width='50' height='50' fill='%23777'/%3E%3C/svg%3E" alt="Full circle and square">
<img class="h-20 w-20 border object-cover" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='80' viewBox='0 0 160 80'%3E%3Crect width='160' height='80' fill='%23ddd'/%3E%3Ccircle cx='32' cy='40' r='25'/%3E%3Crect x='100' y='15' width='50' height='50' fill='%23777'/%3E%3C/svg%3E" alt="Cropped circle and square">
</figure>Class reference
| Class | CSS declarations |
|---|---|
object-contain | object-fit: contain; |
object-cover | object-fit: cover; |
object-fill | object-fit: fill; |
object-scale-down | object-fit: scale-down; |
object-none | object-fit: none; |
View full generated CSS
.object-contain {
object-fit: contain;
}
.object-cover {
object-fit: cover;
}
.object-fill {
object-fit: fill;
}
.object-none {
object-fit: none;
}
.object-scale-down {
object-fit: scale-down;
}