CSS background-position-x Property
Description
The background-position-x property in CSS is used to control the horizontal placement of a background image within an element. By adjusting this property, developers can precisely position a background image along the x-axis without affecting its vertical placement. This can be particularly useful when dealing with complex designs or when layering multiple background images, as it allows for fine-tuned control over how each image aligns within its container. While background-position controls both horizontal and vertical placement together, background-position-x isolates the horizontal component, making adjustments more granular and easier to manage in certain scenarios.
In practical terms, background-position-x can accept values such as keywords (e.g., left, center, right) or length/percentage units (e.g., 50%, 100px). This flexibility allows designers to either anchor the image to a specific edge or position it proportionally within the element. For example, using a percentage value allows the background image to maintain its relative alignment even as the size of the container changes, which is essential for responsive designs. This property works in tandem with background-position-y to fully control image placement, giving developers the ability to independently tweak horizontal and vertical alignments for precise visual results.
It is also worth noting that background-position-x interacts with other background-related properties like background-size and background-repeat. For instance, when a background image is set to cover or contain, the effective horizontal position might appear different than when the image is at its original size, as the image is scaled to fit the container. Similarly, when a background is set to repeat, the starting horizontal position specified by background-position-x determines where the tiling begins. Understanding how background-position-x collaborates with these properties is essential for creating visually consistent and dynamic backgrounds.
Definition
- Initial value
- 0%
- Applies to
- all elements
- Inherited
- no
- Computed value
- A list, each item consisting of: an offset given as a combination of an absolute length and a percentage, plus an origin keyword
- Animatable
- a repeatable list
- JavaScript syntax
- object.style.backgroundPositionX
Interactive Demo
Syntax
background-position-x: left | center | right | <percentage> | <size>
Values
- leftAligns the background to the left. Equivalent to writing 0 or 0%.
- centerAligns the background horizontally to the center. Equivalent to 50% entry.
- rightAligns the background to the right. Record equivalent to 100%.
- <percentage>Sets the background position as a percentage of the elements width. A value of 0% or 0 aligns the left edge of the background image to the left edge of the element. A value of 100% aligns the right edge of the picture with the right edge of the element.
- <size>Sets the position of the background in any units available for CSS - pixels (px), centimeters (cm), em, etc. relative to the left edge of the element.
Example
Browser Support
The following information will show you the current browser support for the CSS background-position-x property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
