Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Colors and Backgrounds

The background-origin property

Reference for CSS background-origin: border-box, padding-box and content-box, how the positioning area differs from the painting area, and live examples.

The background-origin property chooses the positioning area: the box whose top-left corner is the starting point for background-position, and whose size is the reference for percentages and for cover and contain in background-size.

It is easy to confuse with background-clip, which chooses where the background is painted. Origin decides where the image is placed, clip decides how much of it is visible.

CSS
.badge { background-origin: content-box; padding: 20px; }

Try it

Where position 0 0 starts

Syntax

CSS
background-origin: <visual-box>#;

<visual-box> = border-box | padding-box | content-box
  • Initial value: padding-box
  • Applies to: all elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
border-box Position and size are relative to the outer edge of the border. The image starts under the border.
padding-box Relative to the outer edge of the padding, just inside the border. The default.
content-box Relative to the content area, inside the padding.

Usage notes

  • Origin is about placement, not painting. With the defaults, an image placed at 0 0 starts inside the border, but the background still extends under the border because background-clip is border-box. Repeating images therefore show under borders.
  • Percentages and cover follow the origin box. background-size: 100% is as wide as the origin box, not the border box.
  • content-box honors padding. It is a simple way to inset an icon by the same amount as the text, so the two line up without extra positioning.
  • It is ignored with fixed. If background-attachment: fixed applies, the positioning area is the viewport.
  • In the shorthand, a single box value sets both origin and clip. Two values set origin first, then clip. A common surprise: background: url(a.png) content-box; also clips the background to the content box.
  • Layers. Each comma-separated value belongs to the matching image layer.

Browser support

Supported in every browser.