CSS propertyEffects

object-position

Sets the position of an image or video within its box.

Initial value
50% 50%
Inherited
No
Animatable
yes, as a length or percentage
Applies to
replaced elements, e.g. img, video
JavaScript
element.style.objectPosition = "center top"
On this page

Example

#
CSS
.team img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: center top;
}
Preview

Definition and usage

#

The object-position property specifies which part of an image is visible when object-fit crops it to the box, or where the image sits when it is smaller than the box. It works like background-position, but for <img> and <video> elements.

By default the image is centred (50% 50%). For portraits center top often works better so the head isn’t cut off, and for landscapes center bottom.

It accepts keywords, percentages and lengths, first for the horizontal axis, then for the vertical one.

Syntax

#
Syntax
object-position: <x-position> <y-position>?;

Values

#
  • center

    The centre of the image is visible.
  • left

    The left part of the image is visible.
  • right

    The right part of the image is visible.
  • 30% 20%

    percentages

    A precise choice of the visible portion.

Values in practice

#

center

The centre of the image is visible.
.demo { object-position: center; }

left

The left part of the image is visible.
.demo { object-position: left; }

right

The right part of the image is visible.
.demo { object-position: right; }

30% 20%

A precise choice of the visible portion.
.demo { object-position: 30% 20%; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • For photos of people set object-position: center top so the crop doesn’t cut off faces.
  • Without an object-fit other than fill, the image fills the box entirely and the position doesn’t matter.

Related entries

#

Spotted a mistake or missing an example? Write to us.