Home › CSS Tutorial › object-fit and position
object-fit and position
Fit images in fixed boxes.
object-fit (cover, contain, fill) controls cropping. object-position chooses which part stays visible.
Example code
<style>img{width:160px;height:90px;object-fit:cover;object-position:left;border:1px solid #888}</style>
<img alt='Demo' src='data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%27300%27 height=%27300%27%3E%3Crect width=%27150%27 height=%27300%27 fill=%27%23e4572e%27/%3E%3Crect x=%27150%27 width=%27150%27 height=%27300%27 fill=%27%232e86de%27/%3E%3C/svg%3E'>