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"
On this page

Example

#
CSS
.quote {
  padding: 24px;
  background: url("/icons/quote.svg") no-repeat left top / 24px;
  background-origin: content-box;
}
Preview

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

#
Syntax
background-origin: padding-box | border-box | content-box;

Values

#
  • padding-box

    The image starts at the inner edge of the border.
  • border-box

    The image starts under the border.
  • content-box

    The image starts at the content edge, past the padding.

Values in practice

#

padding-box

The image starts at the inner edge of the border.
.demo { background-origin: padding-box; }

border-box

The image starts under the border.
.demo { background-origin: border-box; }

content-box

The image starts at the content edge, past the padding.
.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-box instead of calculating the position in pixels.
  • In the background shorthand, 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.