background-origin
Sets which area of the element the background image position is measured from.
- Initial value
padding-box- Inherited
- No
- Animatable
- no
- Applies to
- all elements
- JavaScript
element.style.backgroundOrigin = "content-box"
Example
#.quote {
padding: 24px;
background: url("/icons/quote.svg") no-repeat left top / 24px;
background-origin: content-box;
}<blockquote style="margin: 0; padding: 16px 16px 16px 16px; border: 1px solid #333; border-radius: 12px; background: url('/collections/nextjs.png') no-repeat right top / 28px; background-origin: content-box;">The icon in the corner keeps the padding gap, because background-origin is content-box.</blockquote>Definition and usage
#The background-origin property defines the reference point for background-position. By default (padding-box), position 0 0 means the top left corner of the padding area, that is the inner edge of the border.
With content-box the image starts at the edge of the content, so the padding creates a gap around it. With border-box the image starts right under the border.
The property matters only for background images and does not affect the background colour. It is often used together with background-clip.
Syntax
#background-origin: padding-box | border-box | content-box;Values
#- The image starts at the inner edge of the border.
- The image starts under the border.
- The image starts at the content edge, past the padding.
Values in practice
#padding-box
.demo { background-origin: padding-box; }border-box
.demo { background-origin: border-box; }content-box
.demo { background-origin: content-box; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- If a background icon should keep a gap from the edge, set
content-boxinstead of calculating the position in pixels. - In the
backgroundshorthand, giving a single box, e.g.content-box, sets both origin and clip.
Related entries
#Spotted a mistake or missing an example? Write to us.