Skip to main content

CSS background-origin Property

Where a background image sits inside an element depends on the CSS background-origin property.

Each of its three values names the edge whose top-left corner the image starts from:

  • padding-box - the padding edge, which is where the image starts by default.
  • border-box - the border edge of the element.
  • content-box - the content edge of the element.

Note: Setting background-attachment to "fixed" leaves this property with no effect.

Example

Three div elements share a border, padding, and a non-repeating background image here, and each one uses a different value of background-origin so you can compare them.

Prompt
Create a page with three div elements, each with a border, padding, and a background image. The first div uses background-origin: padding-box, the second uses border-box, and the third uses content-box. Set background-repeat: no-repeat on all three so the difference in positioning is visible.
Output: complete HTML page