Object Fit and Position

object-fit and object-position governs how "replaced elements" (e.g. <img> or <video>) should fill their container.

CSS Properties

object-fit

Sets how the content of a replaced element should be resized to fit its container.

Specify:

  • fillstretch the object to fill the container (default)
  • nonedon't resize
  • containresize the object to fill the container (maintaining its aspect ratio), ensuring the whole object is "contained" in the container (some part of the container can be empty if the aspect ratios do not match)
  • coverresize the object to fill the container (maintaining its aspect ratio), ensuring the object "covers" the whole container (some part of the object can be clipped to make it fit)
  • scale-downbehave like none or contain, whichever results in smaller object size (basically never scale-up).
| LIVE PREVIEW

object-position

Sets the position (offset) of a replaced element inside its container.

Specify keyword(s) (e.g. left, top left, center), OR up to two lengths/percentages (e.g. 50% 50% or 10px 10px)

| LIVE PREVIEW

Assets

References