CSS / Reference / background-position: Percentages, Centers, and Edge Offsets

CSS background-position controls where a background image sits. center aligns the center of the image with the center of its positioning area. A percentage multiplies the difference between the area size and the rendered image size.

Position an image with keywords and edge offsets

The CSS background-position specification gives 0% 0% as the initial value. A single center centers both axes. A single left aligns horizontally to the left and centers vertically. Two lengths such as 12px 8px offset from the left and top, respectively.

Value Placement Sample
left top Upper-left corner of the positioning area
center Centers the image in the positioning area
right bottom Lower-right corner of the positioning area
right 12px bottom 8px 12px from the right and 8px from the bottom

For a fixed gap from the right or bottom, put each distance after its edge keyword. right 12px bottom 8px leaves 12px on the right of the image and 8px below it. Positive offsets in this syntax move inward from the named edge.

Calculate a percentage position

The horizontal offset is (area width − rendered image width) × percentage. Use heights for the vertical axis. With a 240px area and an 80px image, 50% gives an 80px horizontal offset. background-origin selects the reference box, and background-size controls the image dimensions used in the calculation.

When image and area widths match, there is zero spare horizontal space, so all alignment percentages coincide. If cover makes the image wider than the area, spare space is negative. Moving toward the right anchor reveals more of the image’s right side.

Verify the offsets in a runnable example

Save this as a UTF-8 file named background-position-example.html and open it in a browser. The gradients act as fixed-size background images. No external files are needed.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Background position comparison</title>
  <style>
    body { font: 1rem/1.5 system-ui, sans-serif; margin: 1rem; }
    h1 { overflow-wrap: anywhere; }
    .samples {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(min(100%, 244px), 1fr));
      gap: 1rem;
      max-width: 58rem;
    }
    .tile {
      box-sizing: border-box;
      width: min(100%, 244px);
      height: 104px;
      border: 2px dashed #607d8b;
      background-color: #e6f2ff;
      background-origin: content-box;
      background-clip: content-box;
      background-repeat: no-repeat;
      background-image: linear-gradient(#006c9c, #006c9c);
      background-size: 80px 40px;
    }
    .start { background-position: 0% 0%; }
    .half { background-position: 50% 0%; }
    .end { background-position: 100% 0%; }
    .edge { background-position: right 12px bottom 8px; }

    .layers {
      background-image: linear-gradient(#006c9c, #006c9c),
        linear-gradient(#b95820, #b95820);
      background-size: 48px 24px, 36px 24px;
      background-position: left 8px top 8px, right 12px bottom 8px;
    }
  </style>
</head>
<body>
  <main>
    <h1>Background position comparison</h1>
    <div class="samples">
      <div>
        <p><code>0% 0%</code></p>
        <div class="tile start" aria-hidden="true"></div>
      </div>
      <div>
        <p><code>50% 0%</code></p>
        <div class="tile half" aria-hidden="true"></div>
      </div>
      <div>
        <p><code>100% 0%</code></p>
        <div class="tile end" aria-hidden="true"></div>
      </div>
      <div>
        <p><code>right 12px bottom 8px</code></p>
        <div class="tile edge" aria-hidden="true"></div>
      </div>
      <div>
        <p>Two background layers</p>
        <div class="tile layers" aria-hidden="true"></div>
      </div>
    </div>
  </main>
</body>
</html>

With a 240px content area, the first three boxes place the image at horizontal offsets of 0px, 80px, and 160px. The fourth leaves 12px at the right and 8px at the bottom. Replace 50% 0% with center to center the image vertically as well.

.start { background-position: 0% 0%; }
.half { background-position: 50% 0%; }
.end { background-position: 100% 0%; }
.edge { background-position: right 12px bottom 8px; }

Change .tile from 244px to 204px outer width. The content width becomes 200px. Confirm offsets of 0px, 60px, and 120px in the first three boxes, then restore the original value. On a narrower screen, use the actual content width for the calculation.

Position multiple background images

When background-image contains multiple images, position values match them in list order. The first position below is for the blue image and starts from the left and top. The second is for the orange image and uses the right and bottom.

.layers {
  background-image: linear-gradient(#006c9c, #006c9c),
    linear-gradient(#b95820, #b95820);
  background-size: 48px 24px, 36px 24px;
  background-position: left 8px top 8px, right 12px bottom 8px;
}

A position list with one value is repeated across all layers. If you reorder images, arrange their corresponding sizes and positions to match.

Check a background that appears not to move

If percentage changes have no visible effect, compare the rendered image dimensions with the size of its positioning area first. Temporarily set background-repeat to no-repeat to see the start of one copy clearly.

Check the computed background-position and background-size in developer tools. For an empty element, check its height too. A later background shorthand can reset an earlier position.