W3cubDocs

/CSS

object-position

The object-position CSS property determines the alignment of the selected element inside its box.

/* <position> values */
object-position: center top;
object-position: 100px 50px;

/* Global values */
object-position: inherit;
object-position: initial;
object-position: unset;
Initial value 50% 50%
Applies to replaced elements
Inherited yes
Percentages refer to width and height of element itself
Media visual
Computed value as specified
Animation type repeatable list of simple list of length, percentage, or calc
Canonical order the unique non-ambiguous order defined by the formal grammar

Syntax

Values

<position>
From one to four values that define the 2D position of the element. Relative or absolute offsets can be used. Note that the position can be set outside of the element's box.

Formal syntax

<position>

where
<position> = [[ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ]]

where
<length-percentage> = <length> | <percentage>

Example

HTML

<img id="object-position-1" src="https://mdn.mozillademos.org/files/12668/MDN.svg" alt="MDN Logo"/>
<img id="object-position-2" src="https://mdn.mozillademos.org/files/12668/MDN.svg" alt="MDN Logo"/>

CSS

img {
  width: 300px;
  height: 250px;
  border: 1px solid black;
  background-color: silver;
  margin-right: 1em;
  object-fit: none;
}

#object-position-1 {
  object-position: 10px;
}

#object-position-2 {
  object-position: 100% 10%;
}

Output

Specifications

Specification Status Comment
CSS Images Module Level 4
The definition of 'object-position' in that specification.
Working Draft Adds the from-image and flip keywords.
CSS Images Module Level 3
The definition of 'object-position' in that specification.
Candidate Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 31 16 36 No

19

11.6 -o-

10
Feature Android webview Chrome for Android Edge mobile Firefox for Android Opera Android iOS Safari Samsung Internet
Basic support 4.4.4 ? ? 36

24

11.5 -o-

No ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/object-position