background-origin
Example
.note {
padding: 24px;
background: url("pin.svg") no-repeat left top;
background-origin: content-box;
}'content-box' positions the image from the content edge, so the pin sits inside the 24px padding, aligned with the text.
Common mistakes
- Changing
background-originseems to do nothing because the element has no padding or border. - The background color still fills the border area, because
background-originonly moves images, not where they are painted.
Key points
- Background images that should start inside the padding use
background-origin, not extra margins on the image. - Code doesn't rely on
background-originfor backgrounds that usebackground-attachment: fixed, where it is ignored.
Interview questions
What is the default value of background-origin?
The default is padding-box, so images are positioned from the inner edge of the border.
Does background-origin affect background-color?
No. It only affects background images; use background-clip to control where the color is painted.