Skip to content


Fit image in container

Fits an positions an image appropriately inside its container while preserving its aspect ratio.

<img class="image image-contain" src="" />
<img class="image image-cover" src="" />
.image {
  background: #34495e;
  border: 1px solid #34495e;
  width: 200px;
  height: 200px;

.image-contain {
  object-fit: contain;
  object-position: center;

.image-cover {
  object-fit: cover;
  object-position: right top;

More like this

Start typing a keyphrase to see matching snippets.