CSS background-position property

The background-position property can be used to set the starting point of a background image.

This property is NOT inherited

Possible values

Value Description
top left, top center, top right, center left, center center, center right, bottom left, bottom center, bottom right Specific location where to position the background image
x% y% the horizontal (x) and vertical (y) starting points of the background image in percentage of the elements width and height itself
xPos yPos the horizontal (x) and vertical (y) starting points of the background image

NOTE: If you are using keywords to position a background image - if you specify just one keyword, the second keyword will be "center" by default

NOTE: If you are specifying positioning with percentage, the top left corner is 0% 0% and the bottom right corner is 100% 100%, and if you specify just one value, the other value will be 50% by default.

NOTE: If you are specifying positioning with units, they can be pixels or any other CSS units. The top left corner is 0, 0. If you specify just one value, the other value will be 50% by default.

Example

body { background-image: url(/images/apple.jpg); background-repeat: no-repeat; background-position: top right; }

Output:

This page has a background image in its top right corner

Javascript

You can access this property with Javascript:

element.style.backgroundPosition = "top left";

Other background properties

background
background-attachment
background-color
background-image
background-repeat

CSS background examples

Setting a background color
Setting a background color for a table
Setting a background image for a page
Setting a background image for a table
Setting a background image that does not move
Setting a background image that repeats horizontally
Setting a background image that repeats vertically
Setting a background image that repeats for the whole page
Setting a background image that is center positioned
Setting a background image that is center positioned and does not move
Setting all the background properties with one declaration

More CSS examples

Web Reference
  1. CSS reference
  2. HTML reference
  3. RSS reference

© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation