CSS background-position-x Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The background-position-x property sets the horizontal starting place of each background-image. The place is measured inside the area from background-origin. Vertical place stays as it is, or you set it with background-position-y.

The initial value is 0% (left). The property is not inherited. A later background or background-position declaration overrides it. Pair it with background-repeat: no-repeat when you want one clear marker.

Standard.

Not deprecated. Keywords, lengths, and percentages are Baseline. Side-relative values such as right 20px are widely supported in current browsers. Logical keywords x-start and x-end are newer and still limited.

CSS Syntax

syntax.css
background-position-x: left | center | right | 25% | 20px | right 20px | initial | inherit;

Separate multiple images with commas. The keyword comes before a side offset: right 20px, not 20px right.

Property Values

ValueDescriptionTry it
leftAligns the image to the left edge. Same idea as 0%Try it
centerCenters the image on the horizontal axisTry it
rightAligns the image to the right edge. Same idea as 100%Try it
25%Lines up that point on the image with the same point on the boxTry it
20pxA length offset from the left edge of the positioning areaTry it
right 20pxSide-relative offset. Align to an edge, then nudge inwardTry it
0, centerOne horizontal place per image in a comma-separated listTry it
initialResets this property to 0%Try it
inheritCopies this property from the parent elementTry it

How to Use background-position-x

Give the element an image, keep one copy visible, then set only the horizontal place.

  1. Set a background-image on the element. Without an image, there is nothing to place.
  2. Give the element a visible size. Content or a height is enough.
  3. Use background-repeat: no-repeat when you want one image, not a tile.
  4. Set background-position-x for the horizontal place. Use background-position-y if you also need the vertical place.
PieceRequired?Role
background-imageYesThe picture or gradient you are placing
A visible boxYesContent or a height, so the place has somewhere to show
background-position-xYesHorizontal keyword, percentage, length, or side offset
background-position-yNoVertical place, if you want the axes in separate rules
background-repeatOftenno-repeat keeps a single placed image easy to see

Live Preview

One blue marker, kept vertically centered. Change background-position-x and watch it move left and right.

Vertical place stays center. Only the horizontal place changes.

Horizontal place

background-position-x: center

CSS Examples

Each snippet adds only what background-position-x needs: an image, a sized box, and no-repeat so the mark is clear. Use Try It Yourself for a live editor.

Example 1 — Center Horizontally

Place the marker in the horizontal middle. Vertical place stays center.

CSS
<style>
  div {
    height: 160px;
    border: 1px solid #ccc;
    background-color: #eff6ff;
    background-image: radial-gradient(circle, #2563eb 0 28px, transparent 29px);
    background-repeat: no-repeat;
    background-size: 72px 72px;
    background-position-y: center;
    background-position-x: center;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. Make a box. height: 160px and the border give the image a clear area.
  2. Paint a marker. The radial gradient is a blue circle used as the background image. background-size keeps it small.
  3. Stop the tile. background-repeat: no-repeat shows one circle so horizontal placement is easy to see.
  4. Center on X. background-position-x: center moves only left and right. background-position-y: center keeps the vertical middle steady.

Example 2 — Percentage on X

Line up a horizontal point on the image with the same point on the box.

CSS
<style>
  div {
    height: 160px;
    border: 1px solid #ccc;
    background-color: #ecfdf5;
    background-image: radial-gradient(circle, #059669 0 28px, transparent 29px);
    background-repeat: no-repeat;
    background-size: 72px 72px;
    background-position-y: center;
    background-position-x: 25%;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. One axis only. 25% is horizontal. Vertical place is still center from the other property.
  2. Match points. The point 25% across the image meets the point 25% across the box.
  3. Edges are 0% and 100%. 0% is left. 100% is right. 50% is center.
  4. The image must be smaller. If the image matched the box width, a percentage would have no room to slide. Here the circle is smaller, so the move is visible.

Example 3 — Side Offset

Anchor to the right edge, then nudge inward with a length.

CSS
<style>
  div {
    height: 160px;
    border: 1px solid #ccc;
    background-color: #fff7ed;
    background-image: radial-gradient(circle, #ea580c 0 28px, transparent 29px);
    background-repeat: no-repeat;
    background-size: 72px 72px;
    background-position-y: center;
    background-position-x: right 20px;
  }
</style>

<div></div>
Try It Yourself

How It Works

  1. Name the edge first. right chooses the right edge of the positioning area.
  2. Offset after the edge. 20px follows right, so the circle moves 20px inward from that edge.
  3. Order matters. right 20px is valid. 20px right is not.
  4. Use this for a gap from an edge. Plain right sticks to the edge. The length leaves a small inset.

Edge Cases & Pitfalls

If the horizontal place looks wrong or resets, one of these is usually why.

override

background-position wins later

A later background-position or background rule overrides background-position-x. Set the longhand after the shorthand, or put the place inside the shorthand.

repeat

Tiles hide a clear placement

The initial background-repeat is repeat. Use no-repeat when you want one image so the X place is obvious.

size

A full-width image ignores percentages

If background-size matches the box width, a percentage has no leftover space. Use a length, or make the image narrower than the box.

order

20px right is invalid

A side-relative value needs the keyword first: right 20px or left 25%. A bare length alone is measured from the left.

axis

This property never moves Y

Only the horizontal place changes. For vertical place, use background-position-y or the two-axis background-position shorthand.

Browser Support

background-position-x is a browser painting property. Node.js, Deno, and Bun do not apply it. Keywords, lengths, and percentages are Baseline. Side-relative values and logical keywords have narrower history.

✓ Baseline · Widely available since 2016

background-position-x

Keywords, lengths, percentages: Chrome 1+, Firefox 49+, Safari 1+, Edge 12+, Opera 15+. Side-relative offsets such as right 20px: current Chromium, Firefox, and Safari. Logical x-start / x-end: limited.

98% Keywords and lengths
Google Chrome 1+
Full support
Mozilla Firefox 49+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 15+
Full support
Samsung Internet 1+
Full support
Internet Explorer 6+
Partial
background-position-x Widely supported

Bottom line: Safe for left, center, right, lengths, and percentages in current browsers. Firefox added the property in 49. Side-relative values such as right 20px are fine in current browsers. Prefer physical keywords over x-start / x-end on a normal page.

Key Takeaways

  • Role: set only the horizontal place of each background image.
  • Values: left, center, right, percentages, lengths, or side offsets such as right 20px.
  • Initial value: 0% (left). It is not inherited.
  • Override: a later background or background-position resets this longhand.

One line: background-position-x moves the image left and right — pair it with background-position-y when you also need up and down.

Frequently Asked Questions

It sets only the horizontal place of each background image inside the area from background-origin. Vertical place is unchanged, or controlled with background-position-y. The initial value is 0%, which is the left edge.
0%. That lines up the left edge of the image with the left edge of the positioning area. The property is not inherited.
background-position can set both axes in one declaration. background-position-x sets only the horizontal axis. A later background or background-position rule overrides background-position-x.
Yes. Set horizontal place with background-position-x and vertical place with background-position-y when you want the axes in separate rules.
It is a side-relative value. The image aligns to the right edge, then moves 20px inward from that edge. left 25% works the same way from the left.
Keywords, lengths, and percentages are Baseline and widely available since 2016. Side-relative values such as right 20px have solid support in current browsers. Logical keywords such as x-start are newer and still limited. This is a browser CSS property. Node.js, Deno, and Bun do not paint it.

Next: background-position-y

Learn how to set only the vertical place of a background image.

background-position-y tutorial →

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.

8 people found this page helpful