background-position property

Image Tutorials

Definition and Usage

The background-position CSS property sets the initial position, relative to the background position layer defined by background-origin for each defined background image.

Note: If the value of this property is not set in a background shorthand property that is applied to the element after the background-position CSS property, the value of this property is then reset to its initial value by the shorthand property.

  • Initial0% 0%
  • Applies toall elements
  • Inheritedno
  • Percentagesrefer to the size of the background positioning area minus size of background image; size refers to the width for horizontal offsets and to the height for vertical offsets
  • Mediavisual
  • Computed Valuea list, each item consisting of two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <length>), otherwise as a percentage
  • Animatableyes, as a repeatable list of a simple list of a lengthpercentage or calc(); when both values are lengths, they are interpolated as lengths; when both values are percentages, they are interpolated as percentages; otherwise, both values are converted into a calc() function that is the sum of a length and a percentage (each possibly zero), and these calc() functions have each half interpolated as real numbers.
  • Canonical orderthe unique non-ambiguous order defined by the formal grammar

Syntax

Formal syntax:  <position>#

Values

<position>
Is a <position>, that is one to four values representing a 2D position regarding the edges of the element’s box. Relative or absolute offsets can be given. Note that the position can be set outside of the element’s box.

Examples

01 .exampleone {
02   background-imageurl("logo.png");
03   background-positiontop;
04 }
05 .exampletwo {
06   background-imageurl("logo.png");
07   background-position25% 75%;
08 }
09 .examplethree {
10   backgroundurl("logo.png"2cm bottom;
11 }
12 .examplefour {
13   background-imageurl("logo.png");
14   background-positioncenter 10%;
15 }
16 .examplefive {
17   backgroundurl("logo.png"3em 50%;
18 }
19 .examplesix {
20   background-imageurl("logo.png");
21   background-positionright 20px bottom 20px;
22 }
23 .exampleseven {
24   /* Multiple background images:
25        Each image is matched with the corresponding position style,
26        from first specified to last. */
27   background-imageurl("img1.png"), url("img2.png");
28   background-position0px 0pxcenter;
29 }

Compatibility

Desktop browsers

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 4.0 3.5 1.0 (85)
Multiple backgrounds 1.0 3.6 (1.9.2) 9.0 10.5 1.3 (312)
Four-value syntax (support for offsets from any edge) 25 (maybe earlier) 13.0 (13.0) 9.0 10.5 Nightly (WebKit bug 37514)

Mobile browsers

Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1) (Yes) (Yes) (Yes)
Multiple backgrounds NA 1.0 (1.9.2) NA NA NA
Four-value syntax (support for offsets from any edge) Not supported 13.0 (13.0) NA NA Not supported

Rate article