CSS | object-position Property
The object-position property of CSS specifies how an image or video element is positioned with x/y coordinates inside its content box.
Syntax:
object-position: <position> | initial | inherit
Property alues:
- position: This specifies the position of the element. It takes 2 numerical values corresponding to the distance from the left of the content-box and the distance from the top of the content-box respectively. It is also possible to use negative values.
Example #1:
<!DOCTYPE html><head><title>CSS object-position</title><style>img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* Setting the object-position to '10px'from the leftmost of thebox and '30px' from the topmost of the box */object-position: 10px 30px;}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: 10px 30px</p><imgid="object"src=</body></html>Output:

Example #2:
<!DOCTYPE html><head><title>CSS object-position</title><style>img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* Setting the object-position to '50%'from the leftmost of thebox and '75%' from the topmost of the box */object-position: 50% 75%;}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: 50% 75%</p><imgid="object"src=</body></html>Output:

Example #3:
<!DOCTYPE html><head><title>CSS object-position</title><style>img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* Setting the object-position to 'left'from the leftmost of thebox and 'bottom' from the topmost of the box */object-position: left bottom;}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: left bottom</p><imgid="object"src=</body></html>Output:

Example #4:
<!DOCTYPE html><head><title>CSS object-position</title><style>img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* Setting the object-position to 'center'from the leftmost of thebox and 'top' from the topmost of the box */object-position: center top;}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: center top</p><imgsrc=</body></html>Output:

- initial: This sets the default value of the property, that is 50% 50%, where the element is in the middle of the content box.
Example:
<!DOCTYPE html><head><title>CSS object-position</title><style>img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* sets the default value ofobject-position property */object-position: initial}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: initial</p><imgsrc=</body></html>Output:

- inherit: This receives the property from the parent element. When used with the root element, the initial property is used instead.
Example:
<!DOCTYPE html><head><title>CSS object-position</title><style>#parent {object-position: 60% 80%;}img {width: 300px;height: 250px;background-color: silver;object-fit: none;/* inherits the property of the parent */object-position: inherit;}</style></head><body><h1style="color: green">GeeksforGeeks</h1><p>object-position: inherit</p><divid="parent"><imgsrc=</div></body></html>Output:

Supported Browsers: The browser supported by object-position property are listed below:
- Google Chrome
- Edge
- Firefox
- Opera
- Safari
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


