CSS object-fit & object-position

Control how images and videos fit and align inside their containers

What are object-fit & object-position?

object-fit and object-position are CSS properties that control how replaced elements (like <img> and <video>) are resized and positioned within their containers. They are especially useful for responsive layouts, galleries, and media cards.

Why use them? They provide a simple, CSS-only way to create beautiful, responsive image and video layouts without extra markup or JavaScript.

Interactive Examples

object-fit: cover

Fireman
.fit-cover {
  object-fit: cover;
}

object-fit: contain

Fireman
.fit-contain {
  object-fit: contain;
}

object-fit: none

Fireman
.fit-none {
  object-fit: none;
}

object-fit: cover + object-position: top right

Fireman
.fit-cover-pos {
  object-fit: cover;
  object-position: top right;
}

References & Further Reading