background-position-x CSS property

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.

* Some parts of this feature may have varying levels of support.

The background-position-x CSS property sets the initial horizontal position for each background image. The position is relative to the position layer set by background-origin.

The value of this property is overridden by any declaration of the background or background-position shorthand properties applied to the element after it.

Try it

background-position-x: left;
background-position-x: center;
background-position-x: 25%;
background-position-x: 2rem;
background-position-x: right 32px;
<section class="display-block" id="default-example">
  <div class="transition-all" id="example-element"></div>
</section>
#example-element {
  background-color: navajowhite;
  background-image: url("../../../../../../shared-assets/images/examples/star.png");
  background-repeat: no-repeat;
  height: 100%;
}

Syntax

css
/* Keyword values */
background-position-x: left;
background-position-x: center;
background-position-x: right;

/* <percentage> values */
background-position-x: 25%;

/* <length> values */
background-position-x: 0px;
background-position-x: 1cm;
background-position-x: 8em;

/* Side-relative values */
background-position-x: right 3px;
background-position-x: left 25%;

/* Multiple values */
background-position-x: 0px, center;

/* Global values */
background-position-x: inherit;
background-position-x: initial;
background-position-x: revert;
background-position-x: revert-layer;
background-position-x: unset;

The background-position-x property is specified as one or more values, separated by commas.

Values

left

Aligns the left edge of the background image with the left edge of the background position layer.

center

Aligns the center of the background image with the center of the background position layer.

Aligns the right edge of the background image with the right edge of the background position layer.

<length>

The offset of the given background image's left vertical edge from the background position layer's left vertical edge. (Some browsers allow assigning the right edge for offset).

<percentage>

The offset of the given background image's horizontal position relative to the container. A value of 0% means that the left edge of the background image is aligned with the left edge of the container, and a value of 100% means that the right edge of the background image is aligned with the right edge of the container, thus a value of 50% horizontally centers the background image.

Formal definition

Initial value0%
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Percentagesrefer to width of background positioning area minus width of background image
Computed valueA list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword
Animation typea repeatable list

Formal syntax

background-position-x = 
[ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#

<length-percentage> =
<length> |
<percentage>

Examples

Basic example

The following example shows a background image implementation, with background-position-x and background-position-y used to define the image's horizontal and vertical positions separately.

HTML

html
<div></div>

CSS

css
div {
  width: 300px;
  height: 300px;
  background-color: skyblue;
  background-image: url("https://mdn.dev/archives/media/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png");
  background-repeat: no-repeat;
  background-position-x: center;
  background-position-y: bottom;
}

Result

Side-relative values

The following example shows support for side-relative offset syntax, which allows the developer to offset the background from any edge.

HTML

html
<div></div>

CSS

css
div {
  width: 300px;
  height: 300px;
  background-color: seagreen;
  background-image: url("https://mdn.dev/archives/media/attachments/2020/07/29/17350/3b4892b7e820122ac6dd7678891d4507/firefox.png");
  background-repeat: no-repeat;
  background-position-x: right 20px;
  background-position-y: bottom 10px;
}

Result

Specifications

Specification
CSS Backgrounds Module Level 4
# background-position-longhands

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
background-position-x
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 49 (Release date: 2016-09-20)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 49 (Release date: 2016-09-20)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
Side-relative values (such as left 10%)
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote Full support
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
footnote Removed in 79 and later
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote Full support
Firefox – Full support
Firefox 49 (Release date: 2016-09-20)
footnote Full support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 49 (Release date: 2016-09-20)
footnote Full support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 144 (Release date: 2026-01-13)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
x-end
Experimental
Chrome – No support
Chrome
footnote
footnote See bug 432676117
Edge – No support
Edge
footnote
footnote See bug 432676117
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera
footnote
footnote See bug 432676117
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Chrome Android – No support
Chrome Android
footnote
footnote See bug 432676117
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote
footnote See bug 432676117
Safari on iOS – Full support
Safari on iOS 26 (Release date: 2025-09-15)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote
footnote See bug 432676117
WebView Android – No support
WebView Android
footnote
footnote See bug 432676117
WebView on iOS – Full support
WebView on iOS 26 (Release date: 2025-09-15)
footnote Full support
x-start
Experimental
Chrome – No support
Chrome
footnote
footnote See bug 432676117
Edge – No support
Edge
footnote
footnote See bug 432676117
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera
footnote
footnote See bug 432676117
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Chrome Android – No support
Chrome Android
footnote
footnote See bug 432676117
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote
footnote See bug 432676117
Safari on iOS – Full support
Safari on iOS 26 (Release date: 2025-09-15)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote
footnote See bug 432676117
WebView Android – No support
WebView Android
footnote
footnote See bug 432676117
WebView on iOS – Full support
WebView on iOS 26 (Release date: 2025-09-15)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
Has more compatibility info.

See also