CSS object-position Property

The CSS object-position property specifies how the content of a replaced element, such as an image or video, is aligned within its content box.

It controls the horizontal and vertical positioning of media, especially when the content is cropped or does not completely fill its box. The property is commonly combined with object-fit to control which portions of images remain visible in thumbnails, cards, galleries, and responsive layouts.

object-position Syntax

The object-position property accepts position keywords, percentages, lengths, or combinations of these values.

Basic Syntax

selector {
  object-position: center;
}

Horizontal and Vertical Keywords

img {
  object-position: left top;
}
img {
  object-position: center center;
}
img {
  object-position: right bottom;
}

Percentage Values

img {
  object-position: 50% 50%;
}
img {
  object-position: 75% 25%;
}

Length Values

img {
  object-position: 20px 10px;
}
img {
  object-position: 2rem 1rem;
}

Edge Offsets

img {
  object-position: right 20px bottom 10px;
}

CSS-Wide Keywords

img {
  object-position: initial;
}
img {
  object-position: inherit;
}
img {
  object-position: unset;
}
img {
  object-position: revert;
}
img {
  object-position: revert-layer;
}

The initial value is 50% 50%, which centers the replaced content horizontally and vertically within its box.

Property Values

Value Description
left Aligns the content with the left side of its box.
right Aligns the content with the right side of its box.
top Aligns the content with the top of its box.
bottom Aligns the content with the bottom of its box.
center Centers the content along the applicable axis.
<percentage> Aligns a percentage point of the content with the corresponding percentage point of its box.
<length> Positions the content using an offset measured from the applicable edge.
initial Resets the property to 50% 50%.
inherit Uses the computed value from the parent element.
unset Resets the property to 50% 50% because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 50% 50%
Inherited No
Applies to Replaced elements
Computed value As specified, with relative lengths converted to absolute lengths
Animation type Repeatable list
Common elements <img> and <video>

How It Works

The object-position property determines where replaced content is placed after its size has been established.

The element's content box provides the positioning area. The content itself may be larger, smaller, or the same size as that box.

Centered Image

.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center;
}

The image fills the box and is centered. If cropping is necessary, it is distributed around the center.

Top-Aligned Image

.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center top;
}

The image remains horizontally centered but aligns its top edge with the top of the content box.

Bottom-Aligned Image

.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center bottom;
}

The image remains horizontally centered but aligns its bottom edge with the bottom of the box.

Positioning Does Not Resize Content

The property controls alignment, not scaling. Use object-fit to determine how the content is sized within its box.

Important Consideration

If the replaced content exactly fills the content box in both dimensions, changing object-position may have no visible effect.

Keyword Positioning

Position keywords provide a simple way to align replaced content horizontally and vertically.

Horizontal Alignment

.photo-left {
  object-position: left center;
}
.photo-center {
  object-position: center center;
}
.photo-right {
  object-position: right center;
}

These declarations align the content to the left, center, or right while keeping it vertically centered.

Vertical Alignment

.photo-top {
  object-position: center top;
}
.photo-middle {
  object-position: center center;
}
.photo-bottom {
  object-position: center bottom;
}

These declarations control the vertical alignment while keeping the content horizontally centered.

Corner Alignment

.photo {
  object-position: left top;
}
.photo {
  object-position: right bottom;
}

Two keywords can align content with a particular corner of its box.

Single Keyword

.photo {
  object-position: top;
}

When only one position keyword is provided, the unspecified axis is centered.

Important Consideration

Horizontal and vertical keywords can be combined in either order when the combination is unambiguous.

Percentage Positioning

Percentage values align corresponding points of the replaced content and its content box.

Center Position

.photo {
  object-position: 50% 50%;
}

The center of the content aligns with the center of the box.

Top-Left Position

.photo {
  object-position: 0% 0%;
}

The top-left corner of the content aligns with the top-left corner of the box.

Bottom-Right Position

.photo {
  object-position: 100% 100%;
}

The bottom-right corner of the content aligns with the bottom-right corner of the box.

Custom Position

.photo {
  object-position: 70% 30%;
}

The point 70% across and 30% down the content aligns with the corresponding point in the content box.

How Percentages Are Calculated

The positioning offset along each axis is calculated from the difference between the box dimension and the rendered content dimension.

For example, if the content is 400 pixels wide and the box is 300 pixels wide, the horizontal difference is -100 pixels.

  • 0% produces a horizontal offset of 0 pixels.
  • 50% produces a horizontal offset of -50 pixels.
  • 100% produces a horizontal offset of -100 pixels.

These offsets determine which portion of the oversized content remains visible.

Important Consideration

Percentages do not simply represent a distance measured from the box's top-left corner. They align corresponding percentage positions of the content and the box.

Length Positioning

Length values position content using offsets measured from the applicable edges of the content box.

Pixel Offsets

.photo {
  object-position: 20px 10px;
}

The content is positioned 20 pixels from the left edge and 10 pixels from the top edge.

Root Font Units

.photo {
  object-position: 2rem 1rem;
}

The offsets are calculated relative to the root element's font size.

Negative Offsets

.photo {
  object-position: -30px -15px;
}

Negative values shift the content left and upward relative to its normal top-left alignment.

Calculated Offsets

.photo {
  object-position: calc(50% + 20px) center;
}

The horizontal position combines percentage-based alignment with an additional 20-pixel offset.

Important Consideration

Unlike object-fit, object-position accepts negative length values. These can intentionally shift content beyond the edges of its box.

Edge Offsets

The four-value syntax allows offsets to be measured from specific horizontal and vertical edges.

Right and Bottom Offsets

.photo {
  object-position: right 20px bottom 10px;
}

The right edge of the content is positioned 20 pixels from the right edge of the box, and the bottom edge is positioned 10 pixels from the bottom.

Left and Top Offsets

.photo {
  object-position: left 15px top 25px;
}

The content is positioned 15 pixels from the left and 25 pixels from the top.

Mixed Edge Positioning

.photo {
  object-position: right 10% top 20px;
}

The horizontal position is offset from the right edge using a percentage, while the vertical position is offset from the top using a fixed length.

Three-Value Syntax

.photo {
  object-position: right 20px center;
}

The content is positioned 20 pixels from the right edge and centered vertically.

Important Consideration

Edge-relative syntax is useful when a fixed distance from the right or bottom edge is more meaningful than a distance from the top-left corner.

Using object-position with object-fit

The object-position property is commonly combined with object-fit to control the visible portion of media.

Cover with Center Position

.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center;
}

The image fills the box, and any cropping is distributed around its center.

Cover with Top Position

.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center top;
}

The image fills the box while keeping its upper portion visible when vertical cropping occurs.

Contain with Bottom Position

.photo {
  width: 300px;
  height: 200px;
  object-fit: contain;
  object-position: center bottom;
}

The entire image remains visible and is aligned toward the bottom when unused vertical space is available.

None with Custom Position

.photo {
  width: 300px;
  height: 200px;
  object-fit: none;
  object-position: 75% 25%;
}

The image retains its intrinsic dimensions and is positioned according to the supplied percentages.

Comparison

Property Purpose
object-fit Determines how replaced content is sized within its box.
object-position Determines where the sized content is aligned within its box.

Use both properties when a design requires consistent media dimensions and control over the visible content.

Responsive Images

Responsive layouts often use object-position to adjust image cropping for different screen sizes.

Responsive Card Image

.card-image {
  display: block;
  width: 100%;
  height: 240px;
  object-fit: cover;
  object-position: center;
}

The image fills the card's media area and remains centered as the card width changes.

Adjust Position on Mobile

.hero-image {
  width: 100%;
  height: 350px;
  object-fit: cover;
  object-position: center;
}
@media (max-width: 767px) {
  .hero-image {
    height: 220px;
    object-position: 70% center;
  }
}

The image height and horizontal alignment change on smaller screens to keep a different portion of the image visible.

Responsive Aspect Ratio

.gallery-image {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center top;
}

The image maintains a consistent display ratio while emphasizing its upper portion.

Important Consideration

Changing the element's dimensions can change how much of the media is cropped. Test positioning at different viewport widths to ensure important content remains visible.

object-position vs. background-position

The object-position and background-position properties both control alignment, but they apply to different content.

object-position

<img class="photo" src="photo.jpg" alt="Peacock">
.photo {
  width: 300px;
  height: 200px;
  object-fit: cover;
  object-position: center top;
}

This positions the image content inside the <img> element.

background-position

<div class="photo-background"></div>
.photo-background {
  width: 300px;
  height: 200px;
  background-image: url("photo.jpg");
  background-size: cover;
  background-position: center top;
}

This positions a CSS background image within its background positioning area.

Comparison

Feature object-position background-position
Applies to Replaced content CSS background images
Common elements <img>, <video> Elements with background images
Related sizing property object-fit background-size
Typical use Aligning meaningful image or video content Aligning decorative background imagery

Use object-position for replaced elements and background-position for CSS background images.

Practical Uses

The object-position property helps control the visible area of media in common interface components.

Profile Picture

.avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 25%;
}

The image fills a circular frame while shifting the visible area toward the upper portion of the source.

Card Thumbnail

.card-thumbnail {
  width: 100%;
  height: 220px;
  object-fit: cover;
  object-position: center top;
}

The thumbnail maintains consistent dimensions while keeping the upper part of the image visible.

Product Image

.product-image {
  width: 100%;
  height: 250px;
  object-fit: contain;
  object-position: center bottom;
}

The entire product image remains visible and is aligned toward the bottom of its display area.

Video Preview

.video-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: center;
}

The video content fills a widescreen display box and remains centered when cropping occurs.

Image Gallery

.gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: 60% 40%;
}

The gallery maintains consistent image proportions while emphasizing a selected area of each image.

object-position Example

This example compares five different positions using the same landscape image. Each image uses object-fit: cover, so changing object-position controls which portion of the image remains visible.

HTML Example

<div class="object-position-demo">
  <div class="position-item">
    <h3>center</h3>
    <img class="position-center" src="peacock.jpg" alt="Peacock">
  </div>
  <div class="position-item">
    <h3>left top</h3>
    <img class="position-top-left" src="peacock.jpg" alt="Peacock">
  </div>
  <div class="position-item">
    <h3>right bottom</h3>
    <img class="position-bottom-right" src="peacock.jpg" alt="Peacock">
  </div>
  <div class="position-item">
    <h3>75% 25%</h3>
    <img class="position-percentage" src="peacock.jpg" alt="Peacock">
  </div>
  <div class="position-item">
    <h3>center top</h3>
    <img class="position-top" src="peacock.jpg" alt="Peacock">
  </div>
</div>

CSS Example

.object-position-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
}
.position-item h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}
.position-item img {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  border: 2px solid #64748b;
  box-sizing: border-box;
}
.position-center {
  object-position: center;
}
.position-top-left {
  object-position: left top;
}
.position-bottom-right {
  object-position: right bottom;
}
.position-percentage {
  object-position: 75% 25%;
}
.position-top {
  object-position: center top;
}
Browser Result

center

Peacock

left top

Peacock

right bottom

Peacock

75% 25%

Peacock

center top

Peacock

The image dimensions remain consistent, but the visible portion changes according to the selected position. The differences are most noticeable when the image is cropped along one or both axes.

Responsive Position Example

<img class="responsive-photo" src="peacock.jpg" alt="Peacock">
.responsive-photo {
  display: block;
  width: 100%;
  height: 300px;
  object-fit: cover;
  object-position: center;
}
@media (max-width: 767px) {
  .responsive-photo {
    height: 200px;
    object-position: 70% center;
  }
}

The image uses centered cropping on larger screens and shifts its horizontal alignment on smaller screens.

Common Mistakes

Expecting object-position to Resize an Image

img {
  object-position: center;
}

The property controls alignment, not size. Use object-fit and appropriate element dimensions to control fitting.

Using object-position on Ordinary Containers

.container {
  object-position: center;
}

The property does not position ordinary HTML content inside a container. It applies to replaced elements.

Confusing object-position with background-position

object-position aligns replaced content, while background-position aligns CSS background images.

Expecting Visible Changes When Content Fits Exactly

If the content completely fills its box without excess or unused space, changing its alignment may have no visible effect.

Misunderstanding Percentage Values

Percentages align corresponding points of the content and its box. They are not simply offsets measured from the upper-left corner.

Using Invalid Keyword Combinations

img {
  object-position: left right;
}

Two horizontal alignment keywords cannot be combined this way. Use a valid horizontal and vertical combination such as left top.

Ignoring Cropping on Responsive Screens

The visible image area may change as the element's dimensions change. Test important media at different screen widths.

Expecting object-position to Move the Element

The property moves the replaced content within its box, not the element's box within the page layout. Use layout or positioning properties to move the element itself.

Important Considerations

Keep the following points in mind when using object-position:

  • The property controls the alignment of replaced content within its content box.
  • Its initial value is 50% 50%.
  • The property is not inherited.
  • It applies to replaced elements such as images and videos.
  • It does not resize the element or its content.
  • It is commonly combined with object-fit.
  • Keywords such as left, right, top, bottom, and center provide basic alignment.
  • Percentage values align corresponding points of the content and its box.
  • Length values provide fixed or relative positioning offsets.
  • Negative length values are permitted.
  • Three-value and four-value syntax can position content relative to specific edges.
  • Changing the position may affect which portion of an image is cropped.
  • object-fit: cover is commonly used when consistent image dimensions are required.
  • object-fit: contain can leave unused space that makes alignment visible.
  • The property may have no visible effect when content exactly fills its box.
  • Responsive layouts may require different positions at different viewport widths.
  • background-position applies to CSS background images instead of replaced content.
  • The property can be animated between compatible position values.
  • Positioning does not permanently crop or modify the original media.
  • Test image alignment to ensure important visual details remain visible.

Browser Support

The CSS object-position property is Baseline - Widely available. It is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Keyword, percentage, and length-based positioning are broadly supported in modern browsers. Older browsers may have limitations when positioning replaced content.

For current compatibility information, visit Can I Use? and search for object-position.

When using advanced positioning syntax or animations, verify compatibility with the browsers required by your project.

Specifications

The object-position property is defined in CSS Images Module Level 3.

CSS Images Module Level 3: The object-position Property

The specification defines how replaced content is positioned within its content box, including keyword, percentage, and length-based alignment.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: object-position