CSS Object Fit

Understanding the object-fit Property

The object-fit property specifies how the content of a replaced element (like an <img> or <video> ) should be resized to fit its container.

Tutorials dojo strip
  • contain: Scales the content to fit within the container while maintaining the aspect ratio, possibly leaving some empty space.
CSS
  • cover: Scales the content to cover the container while maintaining the aspect ratio, cropping if necessary.
CSS
  • fill: Stretches the content to fill the container, which may distort the aspect ratio.
CSS
  • none: Keeps the original size of the content, potentially causing overflow.
CSS
  • scale-down: Scales down the content to fit within the container, similar to contain, but only if it’s larger.
CSS

CSS Object Fit Example Code

HTML

CSS Labs

Tutorials dojo strip
Tutorials dojo strip