CSS background-position-x Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Backgrounds & Layout

What You’ll Learn

The background-position-x property controls the horizontal placement of a background image. It lets you move a background left or right without changing its vertical position.

01

Horizontal Axis

Move backgrounds sideways.

02

Keywords

left, center, right.

03

Percentages

Relative x placement.

04

Pixels

Exact left offsets.

05

With position-y

Split axis control.

06

Shorthand

Related to background-position.

Definition and Usage

The background-position-x CSS property sets the horizontal starting position of a background image. It affects placement along the x-axis only, leaving the vertical position to background-position-y or the shorthand background-position.

This is useful when you want to align a decorative icon, badge, or photo to the left, center, or right while keeping vertical placement unchanged.

💡
Beginner Tip

Use a small non-repeating background with a fixed background-size so horizontal movement is easy to see.

📝 Syntax

Apply background-position-x to control horizontal background placement:

syntax.css
selector {

  background-position-x: <position>;

}

Basic Example

background-position-x.css
.panel {

  background-image: url("icon.svg");

  background-repeat: no-repeat;

  background-position-x: 50%;

  background-position-y: top;

}

Syntax Rules

  • The initial value is 0%, which aligns the background to the left.
  • Accepted values include left, center, right, percentages, and lengths.
  • It changes only the horizontal axis.
  • Use background-position-y for vertical control.
  • background-position: center top; is shorthand for both axes together.

⚡ Quick Reference

QuestionAnswer
Initial value0% (left)
Applies toHorizontal background placement
InheritedNo
AnimatableYes
Common useLeft/right icons, centered hero focal points, horizontal offsets

Default Value

The initial value of background-position-x is 0%. That places the background at the left edge of the background positioning area.

💎 Property Values

These are the most common ways to set horizontal background placement with background-position-x.

ValueExampleMeaning
leftbackground-position-x: left;Aligns the background to the left edge
centerbackground-position-x: center;Centers the background horizontally
rightbackground-position-x: right;Aligns the background to the right edge
Percentagebackground-position-x: 50%;Positions relative to element width
Lengthbackground-position-x: 24px;Offsets the background by an exact distance
left

Places the background at the left edge of the positioning area.

Default-like alignment.

center

Centers the background horizontally inside the element.

Common for hero images.

right

Aligns the background to the right edge.

Useful for corner badges.

75%

Moves the background toward the right using a percentage.

Responsive horizontal placement.

background-position-x vs background-position

PropertyControlsBest for
background-position-xHorizontal background placement onlyLeft/center/right alignment without changing y-axis
background-positionBoth horizontal and vertical placementOne-line positioning such as center top
background-position-yVertical background placement onlyTop/center/bottom alignment without changing x-axis

👀 Live Preview

These panels keep the same vertical position and change only the horizontal value:

left
center
right

background-position-y: center; stays the same in all three panels.

Examples Gallery

Try background-position-x with percentages, left/right keywords, pixel offsets, and a multi-value comparison.

📚 Horizontal Placement

Control where a background sits along the x-axis while vertical placement stays separate.

Example 1 — Center Horizontally with 50%

Place a background at the horizontal center while keeping it at the top vertically.

percent-x-position.css
.panel {

  background-image: url("icon.svg");

  background-repeat: no-repeat;

  background-position-x: 50%;

  background-position-y: top;

}
Try It Yourself

How It Works

background-position-x: 50%; centers the background horizontally, while background-position-y: top; keeps it at the top.

Example 2 — left vs right

Compare the two most common horizontal keyword positions.

left-right-x.css
.left { background-position-x: left; }

.right { background-position-x: right; }
Try It Yourself

How It Works

The same background marker moves to opposite horizontal edges using keyword values.

🎨 Exact Horizontal Offsets

Use pixel and percentage values when keywords are not precise enough.

Example 3 — Pixel Offset from the Left

Move a background a fixed distance from the left edge.

pixel-x-position.css
.panel {

  background-position-x: 24px;

  background-position-y: center;

}
Try It Yourself

How It Works

A length value offsets the background horizontally by an exact amount from the left edge.

Example 4 — Compare Horizontal Values

See how different background-position-x values move the same marker sideways.

x-position-compare.css
.left { background-position-x: left; }

.center { background-position-x: center; }

.percent { background-position-x: 75%; }
Try It Yourself

How It Works

Only the horizontal value changes, so the marker moves sideways while staying vertically centered.

🧠 How background-position-x Works

1

You add a background image

Set an image or gradient with background-image.

Background
2

You set the x-axis position

Use background-position-x with left, center, right, percentages, or pixels.

Horizontal rule
3

Vertical placement stays separate

Control the y-axis with background-position-y or the shorthand background-position.

Split axes
=

Precise horizontal control

You can align backgrounds to the left, center, or right without affecting vertical placement.

Universal Browser Support

background-position-x is supported in all modern browsers and works reliably for horizontal background placement.

Baseline · Modern browsers

Control horizontal background placement today

Chrome, Firefox, Safari, Edge, and Opera support keyword, percentage, and length values.

98% Modern browser support
Google Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox49+ · Desktop & Mobile
Full support
Apple Safari15+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera36+ · Modern versions
Full support

Fallback behavior

In older browsers, use the shorthand background-position as a fallback when split-axis properties are unavailable.

💻
Legacy browsers May require background-position instead of split x/y properties
Fallback
background-position-x property 98% supported

Bottom line: Use background-position-x confidently in modern projects, especially with background-position-y for split-axis control.

Conclusion

The background-position-x property gives you direct control over horizontal background placement. It is especially useful when you want to align an image left, center, or right without changing its vertical position.

Pair it with background-position-y for full two-axis control, or use background-position when a single shorthand declaration is enough.

💡 Best Practices

✅ Do

  • Use left, center, and right for simple horizontal alignment
  • Pair with background-position-y when axes need separate control
  • Use percentages for responsive horizontal placement
  • Keep non-repeating backgrounds small when teaching placement
  • Provide a background-position fallback for older browsers if needed

❌ Don’t

  • Confuse background-position-x with the full shorthand property
  • Expect visible movement when the background fully covers the element
  • Forget that the default horizontal position is left (0%)
  • Change x and y in separate places when shorthand would be simpler
  • Ignore focal points on responsive hero images

Key Takeaways

Knowledge Unlocked

Five things to remember about background-position-x

Use these points when placing backgrounds horizontally.

5
Core concepts
📝02

Keywords

left, center, right.

Values
📊03

Percentages

Responsive x placement.

Responsive
04

0% Default

Left edge by default.

Default
🛠05

With position-y

Split axis control.

Compare

❓ Frequently Asked Questions

The background-position-x property sets the horizontal position of a background image. It controls placement along the x-axis without changing the vertical position.
The initial value is 0%, which places the background at the left edge of the background positioning area.
Yes. The common keywords are left, center, and right.
background-position-x controls only the horizontal axis. background-position can set both horizontal and vertical placement in one declaration.
Yes. You can use both properties together to control horizontal and vertical placement separately.

Practice in the Live Editor

Open the HTML editor, move backgrounds horizontally, and experiment with background-position-x instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful