CSS / Reference / background-origin: Positioning References Versus Painting Boundaries
CSS background-origin chooses the box used to position and size a background image. The default is padding-box. Use content-box to start at the content edge or border-box to start at the outer edge of the border.
Choose a positioning box for the background image
The CSS background-origin specification defines the initial value and specifies that the property does not inherit by default. Each blue rectangle below uses background-position: left top. The positioning box is what differs.
| Value | Positioning reference | Starting point |
|---|---|---|
border-box |
Outer edge of the border | |
padding-box |
Inner edge of the border and outer edge of the padding | |
content-box |
Inside the padding at the content edge |
.border { background-origin: border-box; }
.padding { background-origin: padding-box; }
.content { background-origin: content-box; }
Separate placement from the painting area
After you move the positioning box, background-clip still controls where the background can be seen. With background-origin: content-box, the image starts at the content edge. While background-clip is border-box, background-color can still show beneath the border.
Add only background-clip: content-box to the first box. The blue rectangle is outside the new painting area, so it disappears while its position stays the same. Restore border-box after comparing.
Compare the three image starting points
Save this as a UTF-8 file named background-origin-example.html and open it in a browser. The gradient serves as the background image. 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 positioning boxes</title>
<style>
body { font: 1rem/1.5 system-ui, sans-serif; margin: 1rem; }
.demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
max-width: 60rem;
gap: 1rem;
}
.tile {
box-sizing: border-box;
width: min(100%, 260px);
height: 110px;
border: 10px dashed #253a4d;
padding: 20px;
background-color: #eef5fa;
background-image: linear-gradient(#006c9c, #006c9c);
background-position: left top;
background-size: 60px 24px;
background-repeat: no-repeat;
background-clip: border-box;
}
.border { background-origin: border-box; }
.padding { background-origin: padding-box; }
.content { background-origin: content-box; }
</style>
</head>
<body>
<main>
<h1>Background positioning boxes</h1>
<div class="demo">
<div>
<p><code>border-box</code></p>
<div class="tile border" aria-hidden="true"></div>
</div>
<div>
<p><code>padding-box</code></p>
<div class="tile padding" aria-hidden="true"></div>
</div>
<div>
<p><code>content-box</code></p>
<div class="tile content" aria-hidden="true"></div>
</div>
</div>
</main>
</body>
</html>
The boxes have a 10px border and 20px of padding. Measured from the outer upper-left corner, the images start at (0, 0), (10, 10), and (30, 30). The first rectangle extends behind the dashed border.
Calculate percentage sizes and positions
Percentages in background-size use the width or height of the positioning box. When the outer width is 260px, the three positioning widths are 260px, 240px, and 200px. Apply the declarations below to .tile to get image widths of 130px, 120px, and 100px. The offset keeps the first rectangle clear of the border.
.tile {
background-size: 50% 24px;
background-position: left 12px top 12px;
}
A percentage position also accounts for the image size. A horizontal position of 100% offsets the image by the positioning width minus the image width, aligning their right edges. See the CSS background-position percentage rules for details.
Check fixed backgrounds and missing differences
A layer whose background-attachment is fixed ignores background-origin. On a typical screen, it is positioned relative to the viewport, while the element’s painting area can still clip the visible part.
If the three boxes look the same, check whether padding and border are both zero. Inspect the computed background-origin and background-clip values. A later background shorthand can reset an omitted box value.




