CSS background-position-x Property
The background-position-x property in CSS controls the horizontal positioning of a background image within an element.
1. Syntax
2. Accepted Values
| Value | Description |
|---|---|
left (default) | The background image aligns to the left of the element. |
center | The background image aligns to the horizontal center. |
right | The background image aligns to the right. |
<length> | Specifies an exact position in px, em, rem, etc. |
<percentage> | Defines a position relative to the element’s width (e.g., 50% means center). |
3. Example – Using background-position-x: center;
✅ The background image will be horizontally centered.
4. Example – Using background-position-x: right;
✅ The background image will be aligned to the right.
5. Example – Using Length (px or %)
✅ The background image is 50px from the left.
✅ The background image is placed 75% of the way across from the left.
6. Best Practices
✔ Use center for balanced positioning across different screen sizes.
✔ Use % values for responsive layouts.
✔ Combine with background-size for better control.

