CSS | background-position Property
In CSS body-position property is mainly used to set an image at a certain position.
Syntax:
background-position: value;
Property values:
There are a few important property values which can be used to set the image at a certain position.
- initial
- inherit
- left top
- left center
- left bottom
- center top
- center center
- center bottom
- right top
- right center
- right bottom
- x%y%
Note: Here x% denotes the horizontal position and y% denotes the vertical position with respect to the initial position i.e, left top.
- x-pos y-pos
Note: Here the units are represented in pixels or any other CSS units.
Examples of the values of this property:
- background-position: left top; : This property is used to set the image at left top.
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: left top; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: left center; } </style> </head> <body> </body> </html> |
Output :
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: left bottom; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: center top; } </style> </head> <body> </body> </html> |
Output :
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: center center; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: center bottom; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: right top; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: right center; } </style> </head> <body> </body> </html> |
Output
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: right bottom; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: 25% 75&; } </style> </head> <body> </body> </html> |
Output:
<!DOCTYPE html> <html> <head> <title> CSS | background-position Property </title> <style> body { background-image: background-repeat: no-repeat; background-attachment: fixed; background-position: 30px 80px; } </style> </head> <body> </body> </html> |
Output:
Supported Browsers: The browser supported by title attribute are listed below:
- Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM Style backgroundPosition Property
- CSS | transition-property Property
- CSS | nav-down property
- CSS | all Property
- CSS | nav-right property
- CSS | top Property
- CSS | right Property
- CSS border Property
- Web API | DOMRectReadOnly y property
- Web API | DOMRectReadOnly x property
- CSS | transition Property
- Web API | DOMRect right property
- CSS | perspective Property
- CSS | resize Property
- CSS | align-self Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



