background-position

  • Revision slug: CSS/background-position
  • Revision title: background-position
  • Revision id: 21189
  • Created:
  • Creator: Readams
  • Is current revision? No
  • Comment /* Summary */

Revision Content

{{template.CSSRef()}}

Summary

background-position sets the initial position of any background image that has been set.

  • Initial value: 0% 0%
  • Applies to: all elements
  • Inherited: no
  • Percentages: refer to the size of the box itself
  • Media: visual
  • Computed value: for <length> the absolute value, otherwise a percentage

Syntax

background-position: [ [ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit

Values

<percentage> <percentage>
With a value pair of '0% 0%', the upper left corner of the image is aligned with the upper left corner of the box's padding edge. A value pair of '100% 100%' places the lower right corner of the image in the lower right corner of padding area. With a value pair of '14% 84%', the point 14% across and 84% down the image is to be placed at the point 14% across and 84% down the padding area.
<length> <length>
With a value pair of '2cm 1cm', the upper left corner of the image is placed 2cm to the right and 1cm below the upper left corner of the padding area.
top left and left top
Same as '0% 0%'.
top, top center, and center top
Same as '50% 0%'.
right top and top right
Same as '100% 0%'.
left, left center, and center left
Same as '0% 50%'.
center and center center
Same as '50% 50%'.
right, right center, and center right
Same as '100% 50%'.
bottom left and left bottom
Same as '0% 100%'.
bottom, bottom center, and center bottom
Same as '50% 100%'.
bottom right and right bottom
Same as '100% 100%'.

If only one value is specified, then it sets the horizontal position, with the vertical position at 50%. Otherwise, the first value specifies the horizontal position. Combinations are allowed of keyword, length, or percentage values, but if keywords are mixed with other values, 'left' and 'right' may only be used as the first value, and 'top' and 'bottom' may only be used as the second value. Negative positions are allowed.

Examples

.exampleone {
	background-image: url("logo.png");
	background-position: top center;
}

.exampletwo {
	background-image: url("logo.png");
	background-position: 25% 75%;
}

.examplethree {
	background-image: url("logo.png");
	background-position: 2cm bottom;
}

.examplefour {
	background-image: url("logo.png");
	background-position: center 10%;
}

.examplefive {
	background-image: url("logo.png");
	background-position: 2cm 50%;
}

Specifications

Browser Compatibility

TBD: This may be removed in favour of a centralized compatibility chart.

See Also

{{wiki.template('CSS_Reference:Background')}}

Revision Source

<p> 
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p><code>background-position</code> sets the initial position of any background image that has been set.
</p>
<ul><li> Initial value: 0% 0%
</li><li> Applies to: all elements
</li><li> Inherited: no
</li><li> Percentages: refer to the size of the box itself
</li><li> Media: <a href="en/CSS/Media/Visual">visual</a>
</li><li> Computed value: for &lt;length&gt; the absolute value, otherwise a percentage
</li></ul>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval">background-position: [ [ &lt;percentage&gt; | &lt;length&gt; | left | center | right ] [ &lt;percentage&gt; | &lt;length&gt; | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit
</pre>
<h3 name="Values"> Values </h3>
<dl><dt>  &lt;percentage&gt; &lt;percentage&gt;</dt><dd>   With a value pair of '0% 0%', the upper left corner of the image is aligned with the upper left corner of the box's padding edge. A value pair of '100% 100%' places the lower right corner of the image in the lower right corner of padding area. With a value pair of '14% 84%', the point 14% across and 84% down the image is to be placed at the point 14% across and 84% down the padding area.
</dd><dt>  &lt;length&gt;  &lt;length&gt;</dt><dd>  With a value pair of '2cm 1cm', the upper left corner of the image is placed 2cm to the right and 1cm below the upper left corner of the padding area.
</dd><dt>top left and left top</dt><dd> Same as '0% 0%'.
</dd><dt>top, top center, and center top</dt><dd> Same as '50% 0%'.
</dd><dt>right top and top right</dt><dd>Same as '100% 0%'.
</dd><dt>left, left center, and center left</dt><dd>Same as '0% 50%'.
</dd><dt>center and center center</dt><dd>Same as '50% 50%'.
</dd><dt>right, right center, and center right</dt><dd>Same as '100% 50%'.
</dd><dt>bottom left and left bottom</dt><dd>Same as '0% 100%'.
</dd><dt>bottom, bottom center, and center bottom</dt><dd>Same as '50% 100%'.
</dd><dt>bottom right  and right bottom</dt><dd>Same as '100% 100%'.
</dd></dl>
<p>If only one value is specified, then it sets the horizontal position, with the vertical position at 50%.  Otherwise, the first value specifies the horizontal position.  Combinations are allowed of keyword, length, or percentage values, but if keywords are mixed with other values, 'left' and 'right' may only be used as the first value, and 'top' and 'bottom' may only be used as the second value.  Negative positions are allowed.
</p>
<h3 name="Examples"> Examples </h3>
<pre>.exampleone {
	background-image: url("logo.png");
	background-position: top center;
}

.exampletwo {
	background-image: url("logo.png");
	background-position: 25% 75%;
}

.examplethree {
	background-image: url("logo.png");
	background-position: 2cm bottom;
}

.examplefour {
	background-image: url("logo.png");
	background-position: center 10%;
}

.examplefive {
	background-image: url("logo.png");
	background-position: 2cm 50%;
}

</pre>
<h3 name="Specifications"> Specifications </h3>
<ul><li> <a class="external" href="http://www.w3.org/TR/CSS1#background-position">CSS 1</a>
</li><li> <a class="external" href="http://www.w3.org/TR/CSS21/colors.html#propdef-background-position">CSS 2.1</a>
</li><li> <a class="external" href="http://www.w3.org/TR/2005/WD-css3-background-20050216/#background-position">CSS 3</a>
</li></ul>
<h3 name="Browser_Compatibility"> Browser Compatibility </h3>
<p>TBD: This may be removed in favour of a centralized compatibility chart.
</p>
<h3 name="See_Also"> See Also </h3>
<p>{{wiki.template('CSS_Reference:Background')}}
</p>
Revert to this revision