Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Filters, Masks and Shapes

The object-position property

Reference for the CSS object-position property: choose which part of an image or video stays visible inside its box when object-fit crops or leaves space.

The object-position property sets where a replaced element's content (an image, video or canvas) is placed inside the element's box. It only has a visible effect when the content does not exactly fill the box, which happens with object-fit values such as cover, contain, none and scale-down.

Its syntax and behavior match background-position. The default is the center, 50% 50%.

CSS
img.hero {
  width: 300px;
  height: 120px;
  object-fit: cover;
  object-position: 50% 80%;
}

Try it

Choosing the visible part

The wide sunset is scaled to the box height and then cropped sideways. object-position slides the picture left or right behind the fixed frame.

Syntax

CSS
object-position: <position>;
/* examples */
object-position: center;
object-position: left top;
object-position: 25% 75%;
object-position: right 10px bottom 20px;
Initial value 50% 50%
Applies to Replaced elements
Inherited No
Animatable Yes (as a position: lengths and percentages)
Computed value The specified keywords converted to lengths or percentages

Values

Value Description
Keywords left, center, right, top, bottom. One keyword sets one axis and the other defaults to center.
<percentage> Aligns that point of the content with the same point of the box. 0% is the start edge, 100% the end edge, 50% centered.
<length> Offset of the content's top-left corner from the box's top-left corner.
Edge offsets The four-value form such as right 10px bottom 20px offsets from the named edges.

Usage notes

  • Percentages are relative to free space. object-position: 100% 0 aligns the content's right edge with the box's right edge, not the box width itself.
  • No effect on a perfect fit. If the content already matches the box (for example object-fit: fill), there is nothing to move.
  • Focal points. For photos with a subject off-center, set a position (such as top for portraits) so cover cropping keeps the important part.
  • Use responsive values. The crop changes with the box shape, so a position that works on desktop may cut off the subject on a narrow phone layout.
  • Not for background images. Those use background-position.

Browser support

Supported in all current browsers.