Style objectPosition Property

Example

Resize an image to fit its content box, and position the image 5px from the left and 10% from the top inside the content box:

document.getElementById("myImg").style.objectPosition = "0 10%";
Try it Yourself »

Description

The objectPosition property is used to specify how an <img> or <video> should be positioned in its own content box.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
objectPosition 31.0 16.0 36.0 10.1 19.0

Syntax

Return the objectPosition property:

object.style.objectPosition

Set the objectPosition property:

object.style.objectPosition = "position|initial|inherit"

Property Values

Value Description
position Specifies the position of the image or video inside its content box. First value controls the x-asis and the second value controls the y-axis. Can be a string (left, center or right), or a number (in px or %). Negative values are allowed
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: 50% 50%
Return Value: A String or a Number, representing the position of an element in its content box
CSS Version CSS3

Related Pages

CSS tutorial: CSS object-fit

CSS reference: object-position property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.