Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS object-position property

CSS object-position property

Example

Resize the image according to the container size and set the image's position:

img

.a

{

width:

200

px

;

height:

400

px

;

object-fit:

none

;

object-position:

5

px

10

%

;

border:

5

px

solid

red

;

}

Try it »


Tag Definition and Usage Notes

The object-position property is generally used together with object-fitto set the position of an element.

object-position is generally used with img and video tags.

Default value: 50% 50%
Inherited: is.
Animatable: is. About CSS Animations Try it »
Version: CSS3
JavaScript syntax: object.style.objectPosition="0 10%" Try it »

Browser support

The numbers in the table indicate the first browser version that supports this property.

property
object-position 31.0 16.0 36.0 7.1 19.0

Syntax



object-position: position|initial|inherit;

Attribute values

Value Description
position Specifies the position of the image or video within the container. The first value is the x-coordinate and the second value is the y-coordinate. The ways to express this are:

object-position: 50% 50%; object-position: right top; object-position: left bottom; object-position: 250px 125px; | | initial | Sets it to the default value,About initial | | | inherit | Inherits the property from the element's parent. About inherit | |