Change the position of a background-image:
The backgroundPosition property sets or returns the position of a background-image within an element.
The backgroundPosition property is supported in all major browsers.
Return the backgroundPosition property:
Set the backgroundPosition property:
Value | Description |
---|---|
top left top center top right center left center center center right bottom left bottom center bottom right |
If you only specify one keyword, the other value will be "center". |
x% y% | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. |
xpos ypos | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and units |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | 0% 0% |
---|---|
Return Value: | A String, representing the position of a background-image |
CSS Version | CSS1 |
Change the position of the background-image in a <div> element to center bottom:
Change the position of the background-image in a <div> element to 200px horizontal and 40px vertical:
Return the position of the background-image in a <div> element:
CSS tutorial: CSS Background
CSS reference: background-image property
CSS reference: background-position property
HTML DOM reference: background property